-
Notifications
You must be signed in to change notification settings - Fork 10
Project: graphql
- Copy
config.json.template
toconfig.json
and edit credentials to match your SM engine installation. yarn install
node deref_schema.js ./metadataSchemas/
-
yarn run gen-binding
to generatesrc/binding.ts
, which contains the TypeScript types for the GraphQL schema. - Run
yarn run dev
, it will automatically restart Node.JS server when the code changes. - Open
localhost:3010/graphql
in the browser to play with queries.
There are 2 options:
- Make sure port 9229 is open for the graphql container. Add it to
docker-compose.custom.yml
and delete+rebuild the container if needed. - Update the
docker/sm-graphql/docker-entrypoint.sh
file so that the last line contains--inspect=0.0.0.0:9229
beforeserver.js
e.g.exec yarn exec ts-node-dev -- --respawn --inspect=0.0.0.0:9229 server.js
--inspect-brk=0.0.0.0:9229
can also be used if you want it to hit a breakpoint on the first line of code. - Start the graphql container and check its output logs. You should see something like this:
graphql_1 | [INFO] 16:49:00 ts-node-dev ver. 1.1.8 (using ts-node ver. 9.1.1, typescript ver. 3.9.2) graphql_1 | Debugger listening on ws://0.0.0.0:9229/5f849df1-a0fb-4c70-8790-0123456789ab graphql_1 | For help, see: https://nodejs.org/en/docs/inspector graphql_1 | Done generating binding graphql_1 | Done in 0.45s. graphql_1 | 2022-01-04 16:49:13,180 - info: Cron job started
- Open
chrome://inspect
in Chrome. The target should be listed under "Remote target". If not, enable "Discover network targets" and add the 0.0.0.0:9229 target. Click "Inspect" under the target a. The "Sources" tab is the main tab for debugging. b. You may need to add the source code root as a Workspace to make it browsable. c. If you just want to set a single breakpoint, you can just search for the code (Ctrl+Shift+F) without needing to set up the Workspace. - Other debuggers can also be used (VS Code, WebStorm) per the instructions at https://nodejs.org/en/docs/inspector
It's possible to force a breakpoint in code with the debugger
statement, e.g.:
if (someCondition) {
debugger
}
You basically need to set up the same environment outside of Docker - install Node 14 and Yarn, set up your hosts file, then start graphql by running server.js
with ts-node loaded, e.g. with yarn exec ts-node-dev -- --respawn --inspect=9229 server.js
or node --require=ts-node/register server.js
The biggest drawback of this approach is that if you want webapp to connect to graphql, it's a huge pain getting nginx to direct requests outside of Docker. Sometimes it can work by updating the docker/nginx/config/sites-enabled/default
file to refer use 172.17.0.1
(the default host IP address from inside Docker) instead of graphql
, but it's OS-dependent whether this works.
See SQL migrations