Git Product home page Git Product logo

fastify-graphql's People

Contributors

jeromemacias avatar rstacruz avatar sirsavary avatar wtgtybhertgeghgtwtg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

fastify-graphql's Issues

GraphQL responses are serialized twice

Once by runHttpQuery and again by Fastify's bundled JSON serializer.

This is a result of us setting the content-type header to application/json. Serializing twice is inefficient and wasteful and the only obvious fix is a custom implementation of runHttpQuery that does not serialize the GQL response as there appears to be no easy way to disable Fastify's serializer (see fastify/docs/ContentTypeParser)

For the code in question, see GraphQLPlugin.ts#L19

dataSources is not working

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

GraphQL version

Hello,

I just noticed you require graphql on your dependencies. Is this really necessary? I don't see where it's used in the project. I just installed the 0.13 version of graphql in my project and I had to downgrade the version in order to use your plugin.

Thanks!

Error: `Promise may not be fulfilled with 'undefined' when statusCode is not 204`

Ran across the following error when trying out fastify-graphql, here's the simplest reproduction of it I can make :)
First:

npm i fastify graphql fastify-graphql graphql-tools

Then the small test server:

const {graphqlFastify} = require('fastify-graphql')
const {makeExecutableSchema} = require('graphql-tools')
const fastify = require('fastify')({
  logger: true
})

const typeDefs = `
type Test {
    id: ID
}

type Query {
    test: [Test]
}

schema {
    query: Query
}
`
const resolvers = {
  Query: {
    test: () => [{id: '1234'}]
  }
}

const schema = makeExecutableSchema({typeDefs, resolvers})

const port = 3000

fastify.register(graphqlFastify, {
  prefix: '/graphql',
  graphql: {
    schema
  }
})

const start = async () => {
  try {
    await fastify.listen(port)
  } catch (err) {
    fastify.log.error(err)
    process.exit(1)
  }
}
start()

Run the above and then try this curl:

curl http://localhost:3000/graphql?query=query%20%7B%0A%20%20test%20%7B%0A%20%20%20%20id%0A%20%20%7D%0A%7D

Fastify logs the following error:

{
  "level":50,
  "time":1528067153535,
  "msg":"Promise may not be fulfilled with 'undefined' when statusCode is not 204",
  "pid":27185,
  "hostname":"some-host",
  "reqId":1,
  "type":"Error",
  "stack":"Error: Promise may not be fulfilled with 'undefined' when statusCode is not 204\n    at /some/path/example/node_modules/fastify/lib/handleRequest.js:102:31\n    at process._tickCallback (internal/process/next_tick.js:68:7)",
  "v":1
}

cors problems

After registering fastify-cors and graphqlfastify as plugins:

fastify.register(require('fastify-cors'))
fastify.register(graphqlFastify, { prefix: '/graphql', graphql: { schema: require('./schema'), rootValue: 
require('./resolvers'), context: {} }})

requests to /graphql does not contain response header for Allow-Acces-Control-Header: *

screenshot 2018-12-12 at 11 35 42

and the browser block access to the fetch:

Access to fetch at 'http://localhost:3003/graphql' from origin 'http://localhost:3001' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
ApolloError.js:58 Uncaught (in promise) Error: Network error: Failed to fetch
at new ApolloError (ApolloError.js:58)
at QueryManager.js:526
at QueryManager.js:986
at Array.forEach ()
at QueryManager.js:985
at Map.forEach ()
at QueryManager.broadcastQueries (QueryManager.js:981)
at QueryManager.js:481

cannot find any related documentation or Issue....
help ?

No response headers? No Cookies?

Failed to send response header(s)

/**
 * @public
 * @async
 * (Query) Get current user information
 * @returns {Promise<Object>}
 */
Query.test = async ( root, args, ctx, info ) => {
  /** @type {(fastify#FastifyReply|FastifyResponse)} */
  const res = ctx.res;
  res.header('X-test', 'changed');
  return true;
};

Response header:

< HTTP/1.1 200 OK
< X-XSS-Protection: 1; mode=block
< Vary: Origin
< Access-Control-Allow-Credentials: true
< x-test: changed
< content-type: application/json; charset=utf-8
< content-length: 2
< Date: Thu, 14 Feb 2019 17:18:54 GMT
< Connection: keep-alive

Header X-test wasn't sent to response, same issues with cookies.

New release

Can you please release a new patch version ?

Thanks !

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.