File tree Expand file tree Collapse file tree 3 files changed +36
-1
lines changed
Expand file tree Collapse file tree 3 files changed +36
-1
lines changed Original file line number Diff line number Diff line change @@ -582,6 +582,33 @@ graphql(schema, query).then(result => {
582582
583583Or available in the global scope when running on a client as ` jsonSchemaBuilder ` .
584584
585+ ## Plain Schema
586+
587+ If you want to use another server type instead of the built in graphql express,
588+ like apollo-server or etc, you can expose the plain schema to be built into
589+ an executable schema (there may be version issues otherwise).
590+
591+ This uses the export ` getPlainSchema ` .
592+
593+ ``` js
594+ import {ApolloServer } from ' apollo-server' ;
595+ import {makeExecutableSchema } from ' @graphql-tools/schema' ; // or graphql-tools
596+ import {applyMiddleware } from ' graphql-middleware' ;
597+ import {getPlainSchema } from ' json-graphql-server' ;
598+
599+ const data = { };
600+ const schema = applyMiddleware (
601+ makeExecutableSchema (getPlainSchema (data), exampleMiddleware)
602+ );
603+
604+ const server = new ApolloServer ({
605+ schema
606+ });
607+
608+ server .listen ({ port: 3000 });
609+
610+ ```
611+
585612## Deployment
586613
587614Deploy with Heroku or Next.js.
Original file line number Diff line number Diff line change 11import jsonGraphqlExpress from './jsonGraphqlExpress' ;
2- import schemaBuilder from './schemaBuilder' ;
2+ import schemaBuilder , { getPlainSchema as plainSchema } from './schemaBuilder' ;
33
44export const jsonSchemaBuilder = schemaBuilder ;
5+ export const getPlainSchema = plainSchema ;
56export default jsonGraphqlExpress ;
Original file line number Diff line number Diff line change @@ -53,3 +53,10 @@ export default (data) =>
5353 resolvers : resolver ( data ) ,
5454 logger : { log : ( e ) => console . log ( e ) } , // eslint-disable-line no-console
5555 } ) ;
56+
57+ // Same as above, simply returning the object before making it executable.
58+ // This lets you use it with a custom apollo server or etc.
59+ export const getPlainSchema = ( data ) => ( {
60+ typeDefs : printSchema ( getSchemaFromData ( data ) ) ,
61+ resolvers : resolver ( data ) ,
62+ } ) ;
You can’t perform that action at this time.
0 commit comments