Created
March 21, 2023 14:44
-
-
Save PatrikValkovic/9762bd1475a4439905aa393b111d35fc to your computer and use it in GitHub Desktop.
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
import { parse } from 'graphql/language'; | |
import { execute } from 'graphql/execution'; | |
import { validate } from 'graphql/validation'; | |
import { schema } from '../graphql'; | |
export const handler = async (event: APIGatewayEvent): Promise<ApiGatewayProxyResult> => { | |
try { | |
const body = JSON.parse(event.body || ''); | |
const parsed = parse(body.query); | |
const validated = validate(schema, parsed); | |
if (validated.length > 0) | |
return okResponse({ errors: validated }) | |
const result = await execute({ | |
schema, | |
document: parsed, | |
variableValues: body.variables, | |
contextValue: createContext(event), | |
}); | |
return okResponse(result); | |
} catch(err) { | |
return badUserInput(err) | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment