GraphQL

This extension lets you serve an API endpoint made out of your schemas and resolvers.

// register extension
Grown.use(require('@grown/graphql'));

fixture`./example.gql
  type Mutation { noop: Int }
  type Query { truth: Int }
`;

fixture`./resolvers/Test/Query/truth/index.js
  module.exports = function () {
    return 42;
  };
`;

// mount our GraphQL API
server.mount('/', Grown.GraphQL
  .setup([__dirname + '/example.gql'],
    Grown.load(__dirname + '/resolvers')));

Click ▷ RUN above and then ask with your GraphQL client: query { truth } — or try requesting through this link below.


Public methods static

  • setup(schemas, container) — Returns a middleware ready to be mounted into the server instance. Given schemas are expected to be an array of *.gql files and container is the implementation.

Private* methods static

  • _startGraphQLServer(typeDefs, resolvers) — Used by setup() to build the GraphQL middleware.
  • _bindGraphQLServer(schemas, container) — Used by setup() to decorate the given resolvers.