Skip to content
This repository was archived by the owner on Sep 11, 2019. It is now read-only.
This repository was archived by the owner on Sep 11, 2019. It is now read-only.

Using prepare and extraContext is confusing #91

@wujashek

Description

@wujashek

Thanks for a great library !

While checking how to extract schema from gramps I've found great example here: https://gramps.js.org/api/gramps/

I had an issue with this part, seems context doesn't get a request object in such setup:

app.use('/graphql',
  bodyParser.json(),
  gramps.addContext,         // Add the extra context
  graphqlExpress({
    schema,                  // Use the merged schema...
    context: gramps.context, // ...and the GrAMPS context object
  }),
);

So I had to rewrite it to:

app.use('/graphql',
  bodyParser.json(),
  gramps.addContext,         // Add the extra context
  graphqlExpress(req => ({
    schema,                  // Use the merged schema...
    context: gramps.context(req), // ...and the GrAMPS context object
  })),
);

Also I've noticed extraContext callback is called twice for a single query.

addContext: (req, res, next) => {
      req.gramps = getContext(req);
      next();
    }

Maybe the idea is to pass req.gramps to apollo express middleware as config object ?

It would be great to see some clarification on above so I can work on PR to improve that ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions