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

Syntax for Setting up with Apollo Server 2? #24

Closed
zakayothuku opened this issue Apr 10, 2019 · 1 comment
Closed

Syntax for Setting up with Apollo Server 2? #24

zakayothuku opened this issue Apr 10, 2019 · 1 comment

Comments

@zakayothuku
Copy link

Anyone who has implemented this with Apollo Server 2? There is no example showing how to set up this.

Tried this but keeps throwing undefined errors

const server = new ApolloServer({
    typeDefs: importSchema('./src/schema.graphql'),
    resolvers: resolvers as any,
    introspection: true,
    playground: process.env.NODE_ENV === 'development',
    debug: process.env.NODE_ENV === 'development',
    context: async ({req}) => {
        return {
            req,
            db
        }
    },
    formatError: error => {
        console.log('Error', error);
        switch (error.extensions.code) {
            case 'INTERNAL_SERVER_ERROR':
                delete error.extensions.exception;
                error.message = 'Internal server error. Try again later';
                return error;
            default:
                return error;
        }
    },
    validationRules: [
        costAnalysis({
            variables: graphQLParams.variables,
            maximumCost: 1000,
        }),
    ],
});

Any help would be greatly appreciated.

@zakayothuku zakayothuku changed the title Syntax for Apollo Server 2? Syntax for Setting up with Apollo Server 2? Apr 10, 2019
@pa-bru
Copy link
Owner

pa-bru commented Apr 19, 2019

Hi, from what I see in the snippet above graphQLParams is not defined. To set up graphql-cost-analysis with apollo-server 2 you have to use a workaround available here #12 to pass the request's variables to the variables property of the costAnalysis object.

@pa-bru pa-bru closed this as completed Apr 19, 2019
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

2 participants