mirror of
https://github.com/FranP-code/countries.git
synced 2025-10-13 00:02:15 +00:00
Use netlify functions
This commit is contained in:
35
netlify/functions/graphql/graphql.js
Normal file
35
netlify/functions/graphql/graphql.js
Normal file
@@ -0,0 +1,35 @@
|
||||
import {ApolloServer, gql} from 'apollo-server-lambda';
|
||||
import {ApolloServerPluginLandingPageGraphQLPlayground} from 'apollo-server-core';
|
||||
import {buildSubgraphSchema} from '@apollo/subgraph';
|
||||
import {join} from 'path';
|
||||
import {readFileSync} from 'fs';
|
||||
import {resolvers} from './resolvers';
|
||||
|
||||
const typeDefs = gql(
|
||||
readFileSync(join(__dirname, '../../../schema.graphql')).toString()
|
||||
);
|
||||
|
||||
const schema = buildSubgraphSchema({
|
||||
typeDefs,
|
||||
resolvers
|
||||
});
|
||||
|
||||
const server = new ApolloServer({
|
||||
schema,
|
||||
introspection: true,
|
||||
plugins: [ApolloServerPluginLandingPageGraphQLPlayground()]
|
||||
});
|
||||
|
||||
const apolloHandler = server.createHandler();
|
||||
|
||||
// workaround for netlify dev to play nice with ac3
|
||||
// from https://github.com/vendia/serverless-express/issues/427#issuecomment-924580007
|
||||
export const handler = (event, context, ...args) =>
|
||||
apolloHandler(
|
||||
{
|
||||
...event,
|
||||
requestContext: context
|
||||
},
|
||||
context,
|
||||
...args
|
||||
);
|
||||
Reference in New Issue
Block a user