1
1
/**
2
2
* This code assumes you have other graphql Netlify functions
3
3
* and shows you how to stitch them together in a "gateway".
4
- *
4
+ *
5
5
* Of course, feel free to modify this gateway to suit your needs.
6
6
*/
7
7
8
-
9
8
const {
10
9
introspectSchema,
11
10
makeRemoteExecutableSchema,
12
- mergeSchemas,
13
- } = require ( "graphql-tools" )
14
- const { createHttpLink } = require ( "apollo-link-http" )
15
- const fetch = require ( "node-fetch" )
16
- const { ApolloServer, gql } = require ( "apollo-server-lambda" )
11
+ mergeSchemas
12
+ } = require ( "graphql-tools" ) ;
13
+ const { createHttpLink } = require ( "apollo-link-http" ) ;
14
+ const fetch = require ( "node-fetch" ) ;
15
+ const { ApolloServer, gql } = require ( "apollo-server-lambda" ) ;
17
16
18
17
exports . handler = async function ( event , context ) {
19
- const schema1 = await getSchema ( "graphql-1" ) // other Netlify functions which are graphql lambdas
20
- const schema2 = await getSchema ( "graphql-2" ) // other Netlify functions which are graphql lambdas
21
- const schemas = [ schema1 , schema2 ]
18
+ const schema1 = await getSchema ( "graphql-1" ) ; // other Netlify functions which are graphql lambdas
19
+ const schema2 = await getSchema ( "graphql-2" ) ; // other Netlify functions which are graphql lambdas
20
+ const schemas = [ schema1 , schema2 ] ;
22
21
23
22
// /**
24
23
// * resolving -between- schemas
@@ -51,22 +50,25 @@ exports.handler = async function(event, context) {
51
50
// }
52
51
53
52
// more docs https://www.apollographql.com/docs/graphql-tools/schema-stitching#api
54
- const schema = mergeSchemas ( { schemas, resolvers } )
55
- const server = new ApolloServer ( { schema } )
53
+ const schema = mergeSchemas ( {
54
+ schemas
55
+ // ,resolvers
56
+ } ) ;
57
+ const server = new ApolloServer ( { schema } ) ;
56
58
return new Promise ( ( yay , nay ) => {
57
- const cb = ( err , args ) => ( err ? nay ( err ) : yay ( args ) )
58
- server . createHandler ( ) ( event , context , cb )
59
- } )
60
- }
59
+ const cb = ( err , args ) => ( err ? nay ( err ) : yay ( args ) ) ;
60
+ server . createHandler ( ) ( event , context , cb ) ;
61
+ } ) ;
62
+ } ;
61
63
62
64
async function getSchema ( endpoint ) {
63
65
// you can't use relative URLs within Netlify Functions so need a base URL
64
66
// process.env.URL is one of many build env variables:
65
67
// https://www.netlify.com/docs/continuous-deployment/#build-environment-variables
66
68
// Netlify Dev only supports URL and DEPLOY URL for now
67
- const uri = process . env . URL + "/.netlify/functions/" + endpoint
68
- const link = createHttpLink ( { uri, fetch } )
69
- const schema = await introspectSchema ( link )
70
- const executableSchema = makeRemoteExecutableSchema ( { schema, link } )
71
- return executableSchema
72
- }
69
+ const uri = process . env . URL + "/.netlify/functions/" + endpoint ;
70
+ const link = createHttpLink ( { uri, fetch } ) ;
71
+ const schema = await introspectSchema ( link ) ;
72
+ const executableSchema = makeRemoteExecutableSchema ( { schema, link } ) ;
73
+ return executableSchema ;
74
+ }
0 commit comments