Dgraph Directives reference (for other tools)?

Since this is indexed and others may come for a similar issue:

The final solution that seems to work really well is below.
My specific case is using gqlgen to generate gql server stub from the active dgraph gql schema, but the same idea should work just as well for any other ci/cd/auto pipelines.

The curl command uses the recommendation from @rajas, and just adds python/jq for clean pipe-to-schema-file.

I translated my Taskfile to bash, so please don’t copy-paste.

# routine cleanup
rm -f gql-srv/graph/schema.graphqls

# get generated schema from /admin endpoint.
#  use python and jq to pluck .data.getGQLSchema.generatedSchema from response and pass to schema file
curl 'http://localhost:8080/admin' \
    -H 'Content-Type: application/json' \
    --data-binary '{"query":"query{getGQLSchema{generatedSchema}}"}' | 
    python -m json.tool | jq -r '.data.getGQLSchema.generatedSchema' \
        > gql-srv/graph/schema.graphqls

# regenerate gql server stub from updated .graphqls
cd gql-srv && gqlgen generate
2 Likes