-
-
Notifications
You must be signed in to change notification settings - Fork 674
Closed
Labels
Question ❔Not future request, proposal or bug issueNot future request, proposal or bug issueSolved ✔️The issue has been solvedThe issue has been solved
Description
How would I use this library in a lambda execution model?
I tried to implement it as follows, but on the second (and subsequent) calls to the endpoint, I get an error which states:
Schema must contain unique named types but contains multiple types named "Person"
I assume that this is because the schema is being re-built on every request, and therefore creating duplicated types?
handler.ts
import 'reflect-metadata';
import { graphqlLambda } from 'apollo-server-lambda';
import { buildSchema } from 'type-graphql';
import { PeopleController } from './controllers/people/peopleController';
export async function graphqlHandler(event, context, callback) {
function callbackWithHeaders(error, output) {
output.headers['Access-Control-Allow-Origin'] = '*';
callback(error, output);
}
const schema = await buildSchema({
resolvers: [PeopleController]
});
const handler = graphqlLambda({ schema: schema });
return handler(event, context, callbackWithHeaders);
}
person.ts:
import { ID, Field, ObjectType } from 'type-graphql';
@ObjectType()
export class Person {
@Field() name: string;
@Field() creationDate: Date;
}
peopleController.ts
import { Arg, Query, Resolver } from 'type-graphql';
import { Person } from './person';
@Resolver()
export class PeopleController {
items: Person[] = [
{
name: 'darbio',
creationDate: new Date()
}
];
@Query(returns => [Person], { description: 'Get all the people' })
async people(): Promise<Person[]> {
return await this.items;
}
}
Metadata
Metadata
Assignees
Labels
Question ❔Not future request, proposal or bug issueNot future request, proposal or bug issueSolved ✔️The issue has been solvedThe issue has been solved