Plugin to generate a single schema file, to be consumed by Relay #2255
davidkus
started this conversation in
Show and tell
Replies: 0 comments
# for free
to join this conversation on GitHub.
Already have an account?
# to comment
-
TLDR: Plugin to generate a single GraphQL schema file for the generated server, which can then be consumed by Relay.
In trying to get EntGo + gqlgen + Relay to work together, I ran into a few issues:
type Mutation
. It also only generates a strict set ofQueries
- and I had a need for some custom queries.Solution: Use multiple schema files, which gqlgen happily supports. In addition to the schema file generated by entgo, I included a hand-written one that contained the mutation definitions, as well as some custom queries by extending the
Query
type, e.g.:Solution: Concatenate my two schema files together, à la
cat schema1.graphql schema2.graphql > combined_schema.graphql
.extend type
to achieve this. Long story short, Relay does not send anything defined in anextend type
to the server. So, my custom queries were not being sent.Solution: Using gqlgen's plugin framework, generate a schema file based on all definitions known by the generated server. Leverages github.com/vektah/gqlparser - which is an existing dependency of gqlgen.
The Plugin:
This will actually generate the "effective schema" - all
extend type
s will be merged into the basetype
.So these two files:
Are merged into this single file:
Hopefully this can save someone from a headache when using gqlgen with Relay.
Beta Was this translation helpful? Give feedback.
All reactions