Skip to content

Instantly share code, notes, and snippets.

@PatrikValkovic
Created March 21, 2023 14:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PatrikValkovic/9762bd1475a4439905aa393b111d35fc to your computer and use it in GitHub Desktop.
Save PatrikValkovic/9762bd1475a4439905aa393b111d35fc to your computer and use it in GitHub Desktop.
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