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

express-graphql / graphqlHTTP implementation example #51

Open
bouviervj opened this issue Oct 21, 2022 · 0 comments
Open

express-graphql / graphqlHTTP implementation example #51

bouviervj opened this issue Oct 21, 2022 · 0 comments

Comments

@bouviervj
Copy link

Thank you for you great job - I was looking to implement the server version on the express-graphql stack here is my implementation as an example - not perfect but works:

     // schema is the initial schema you wanted to deploy

     schema = extendSchema(
      schema,
      lodashDirectiveAST,
    );

    app.use('/graphql', (...args) => {

      graphqlHTTP({
        schema: schema,
        graphiql: true,
        customParseFn : (source) => {

          // get the query from the body
          let body = source.body;

          // Process the lodash parsing
          let { query, transform } = graphqlLodash(body);

          // Replace the body in the Source instance
          source.body = query;

          // Use the standard parse method
          let documentAST = graphql.parse(source);

          // store the transform in the document, an element conveyed in customExecuteFn
          documentAST.transform = transform;

          return documentAST;

        },
        customExecuteFn : async ( { document, ...args } ) => {

          // Execut first
          let result = await graphql.execute( { document: document, ...args });

          // Then back transform the query.
          result.data = document.transform(result.data);

          // Return the result
          return result;

        }
      })(...args);

    });

  • cheers -
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