-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #321 from the-hideout/graphql-yoga
Graphql yoga
- Loading branch information
Showing
44 changed files
with
3,368 additions
and
2,881 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
18.16.0 | ||
20.11.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { createYoga, useExecutionCancellation } from 'graphql-yoga' | ||
import { v4 as uuidv4 } from 'uuid'; | ||
|
||
import DataSource from './datasources/index.mjs'; | ||
import schema from './schema.mjs'; | ||
import graphqlUtil from './utils/graphql-util.mjs'; | ||
import graphQLOptions from './utils/graphql-options.mjs'; | ||
|
||
import useRequestTimer from './plugins/plugin-request-timer.mjs'; | ||
import useHttpServer from './plugins/plugin-http-server.mjs'; | ||
import useCacheMachine from './plugins/plugin-use-cache-machine.mjs'; | ||
import useTwitch from './plugins/plugin-twitch.mjs'; | ||
import useNightbot from './plugins/plugin-nightbot.mjs'; | ||
import usePlayground from './plugins/plugin-playground.mjs'; | ||
import useOptionMethod from './plugins/plugin-option-method.mjs'; | ||
|
||
let dataAPI, yoga; | ||
|
||
export default async function getYoga(env) { | ||
if (!dataAPI) { | ||
dataAPI = new DataSource(env); | ||
} | ||
if (yoga) { | ||
dataAPI.env = env; | ||
return yoga; | ||
} | ||
yoga = createYoga({ | ||
schema: (context) => { | ||
// this context only has the env vars present on creation | ||
context.request.requestId = uuidv4(); | ||
if (env.ctx) { | ||
context.request.ctx = env.ctx; | ||
} | ||
if (context.ctx) { | ||
context.request.ctx = context.ctx; | ||
} | ||
return schema(dataAPI, graphqlUtil.getDefaultContext(dataAPI, context.request.requestId)); | ||
}, | ||
context: async ({request, params}) => { | ||
return graphqlUtil.getDefaultContext(dataAPI, request.requestId); | ||
}, | ||
plugins: [ | ||
//useExecutionCancellation(), | ||
useRequestTimer(), | ||
useOptionMethod(), | ||
useTwitch(env), | ||
usePlayground(), | ||
useNightbot(env), | ||
useHttpServer(env), | ||
useCacheMachine(env), | ||
], | ||
cors: { | ||
origin: graphQLOptions.cors.allowOrigin, | ||
credentials: true, | ||
allowedHeaders: ['Content-Type'], | ||
methods: graphQLOptions.cors.allowMethods.split(', '), | ||
}, | ||
}); | ||
return yoga; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.