sirsavary / fastify-graphql

Run an Apollo Server on Fastify.
https://www.npmjs.com/package/fastify-graphql
MIT License
24 stars 5 forks source link

dataSources is not working #15

Open iEricKoh opened 6 years ago

iEricKoh commented 6 years ago

I am trying follow the official doc to use data source in my resolvers. However, there's no field name dataSources exists on context.

I am wondering if the dataSources is acceptable when I try to register the plugin?

const resolvers = {
  Query: {
    product: async (_source: any, args: any, context: any) => {
      console.log(args)
      console.log(context) // no dataSources in the context
      return {
        id: 1
      }
    }
  },
};
    server.register(graphqlFastify, { 
      prefix: '/graphql', 
      graphql: {
        schema,
        dataSources: () => {
          console.log('The log doesn\'t print')
          return {
            productAPI: new ProductAPI(),
          };
        },
        context: () => {
          return {
            token: 'foo',
          };
        },
        tracing: true,
        cacheControl: {
          defaultMaxAge: 500,
          stripFormattedExtensions: false,
          calculateCacheControlHeaders: false,
        },
        cache: new RedisCache({
          host: '127.0.0.1'
        })
      },
    });

https://www.apollographql.com/docs/apollo-server/features/data-sources.html