Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connect Prisma Bindings to mock server #359

Open
RoryKelly opened this issue Mar 19, 2019 · 0 comments
Open

Connect Prisma Bindings to mock server #359

RoryKelly opened this issue Mar 19, 2019 · 0 comments

Comments

@RoryKelly
Copy link

RoryKelly commented Mar 19, 2019

I can mock a generic graphQL service with graphql-tools

I cannot use these tools with prisma binding as I cannot pass prisma-bindings an executable schema.

Current work around

create file schema.ts

const schemaPath = path.format({dir: __dirname, base: '../generated/prisma.graphql'}).toString();
export const typeDefs = gql(importSchema(schemaPath));

add below to package.json

 "generate": "graphql-binding --language typescript --input src/mocks/Schema.ts --outputBinding 
src/mocks/generated/MockPrismaBinding.ts"

Then create a file MockPrisma.ts

export const MockPrisma = ( mockList: IMocks, typeResolvers = undefined) => {
    // Add mocks, modifies schema in place
    const schema = makeExecutableSchema({ typeDefs, resolvers: typeResolvers});
    addMockFunctionsToSchema({ schema , mocks: mockList});
    const link = new SchemaLink({schema});
   // custom binding generate with graphql-binding --language typescript
    return new MockPrismaBindings.Binding(link);
};

Can now mock in tests like this

  const prisma = MockPrisma({
            CurationTag: (source, args) =>
                ({
                    curations: [],
                    user: null,
                    id: args.where.id,
                    name: 'comedy',
                } as CurationTag)
        });

const result = await Resolver.type(null, {ids:[]}, {db: prisma} as Context, null);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant