How to modulate GraphQL schema when using `buildSchema`?

About a year has passed since I updated my graphql-js dependency. Now I see that there is a utility that simplifies the creation of the scheme: buildSchema. This function accepts, like arg, your entire schema as a string, in GraphQL. This is awesome, but is there a way to modulate it? My circuit is not very small and suck in one file .graphql. Is there some kind of utility or template for storing the definition of each type in its own file, for example?

+4
source share
3 answers

If you have a package graphql-tools, you can use makeExecutableSchemato modulate your circuit as follows:

const schema = makeExecutableSchema({
    typeDefs: [schema1, schema2, schema3, ...],
    resolvers: resolvers,
});

, .

+3

merge-graphql-schemas.

graphql - graphql-server-seed

. , !

0

If you are using Apollo graphical tools, I have found that the best way to structure your circuit is to use schemaglue.js (disclaimer: I created this):

const { makeExecutableSchema } = require('graphql-tools')
const { glue } = require('schemaglue')

const { schema, resolver } = glue('src/graphql')

const executableSchema = makeExecutableSchema({
    typeDefs: schema,
    resolvers: resolver
})

And then you can structure your schema and resolvers with something similar to this:

- src/
   |__ graphql/
          |__ product/
          |       |__ schema.js
          |       |__ resolver.js
          |
          |__ variant/
                  |__ schema.js
                  |__ resolver.js

- index.js
- package.json

I wrote a detailed article about this here .

0
source

Source: https://habr.com/ru/post/1676038/


All Articles