Skip to content

Commit 1803a3c

Browse files
committed
Export get plain schema, modify readme with example.
1 parent 715cb16 commit 1803a3c

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,33 @@ graphql(schema, query).then(result => {
582582

583583
Or 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

587614
Deploy with Heroku or Next.js.

src/node.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import jsonGraphqlExpress from './jsonGraphqlExpress';
2-
import schemaBuilder from './schemaBuilder';
2+
import schemaBuilder, { getPlainSchema as plainSchema } from './schemaBuilder';
33

44
export const jsonSchemaBuilder = schemaBuilder;
5+
export const getPlainSchema = plainSchema;
56
export default jsonGraphqlExpress;

src/schemaBuilder.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff 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+
});

0 commit comments

Comments
 (0)