HomeServicesOfAmerica / moleculer-graphql

[Archived] GraphQL Schema stitching over a microservice network for co-located type definitions.
GNU General Public License v3.0
48 stars 17 forks source link

Add graphqlContext to object passed to service call #14

Closed alobodig closed 4 years ago

alobodig commented 6 years ago

This will allow the GraphQL context to be available to the services.

Here is an example use case which will pass user information from a request handled by graphqlHTTP to a service.

app.use('/graphql', graphqlHTTP((request, response) => ({
    schema: gateway.schema,
    context: { user: request.user },
})));

Then in a service:

const GraphQLMixin = createGraphqlMixin({
    typeName: 'Example',
    schema,
    resolvers: {
        Query: {
            async example(_, {}, context, info) {
                console.log(context.params.graphqlContext.user); // this is now available
            },
        },
    },
});