Repository: mcollina/fastify-gql
Pull request #148 (2020-05-04 18:03:17)

fix: typo in reply
I found this typo by accident and thought it would be nice to create a PR to fix it :)


Patch:
diff --git a/index.d.ts b/index.d.ts
index 4112582..0cfb907 100644
--- a/index.d.ts
+++ b/index.d.ts
@@ -1,6 +1,5 @@
 import fastify, { FastifyError, FastifyReply, FastifyRequest, RegisterOptions } from "fastify";
-import { DocumentNode, ExecutionResult, GraphQLSchema, Source } from 'graphql';
-import { IResolvers } from "graphql-tools";
+import { DocumentNode, ExecutionResult, GraphQLSchema, Source, GraphQLResolveInfo, GraphQLIsTypeOfFn, GraphQLTypeResolver, GraphQLScalarType } from 'graphql';
 import { IncomingMessage, Server, ServerResponse } from "http";
 import { Http2Server, Http2ServerRequest, Http2ServerResponse } from 'http2';
 
@@ -188,3 +187,71 @@ declare function fastifyGQL<
 
 
 export = fastifyGQL;
+
+interface IResolvers<TSource = any, TContext = any> {
+  [key: string]: (() => any) | IResolverObject<TSource, TContext> | IResolverOptions<TSource, TContext> | GraphQLScalarType | IEnumResolver;
+}
+
+type IResolverObject<TSource = any, TContext = any, TArgs = any> = {
+  [key: string]: IFieldResolver<TSource, TContext, TArgs> | IResolverOptions<TSource, TContext> | IResolverObject<TSource, TContext>;
+};
+
+interface IResolverOptions<TSource = any, TContext = any, TArgs = any> {
+  fragment?: string;
+  resolve?: IFieldResolver<TSource, TContext, TArgs>;
+  subscribe?: IFieldResolver<TSource, TContext, TArgs>;
+  __resolveType?: GraphQLTypeResolver<TSource, TContext>;
+  __isTypeOf?: GraphQLIsTypeOfFn<TSource, TContext>;
+}
+
+type IEnumResolver = {
+  [key: string]: string | number;
+};
+
+type IFieldResolver<TSource, TContext, TArgs = Record<string, any>> = (source: TSource, args: TArgs, context: TContext, info: GraphQLResolveInfo & {
+  mergeInfo: MergeInfo;
+}) => any;
+
+type MergeInfo = {
+  delegate: (type: 'query' | 'mutation' | 'subscription', fieldName: string, args: {
+      [key: string]: any;
+  }, context: {
+      [key: string]: any;
+  }, info: GraphQLResolveInfo, transforms?: Array<Transform>) => any;
+  delegateToSchema<TContext>(options: IDelegateToSchemaOptions<TContext>): any;
+  fragments: Array<{
+      field: string;
+      fragment: string;
+  }>;
+};
+
+type Transform = {
+  transformSchema?: (schema: GraphQLSchema) => GraphQLSchema;
+  transformRequest?: (originalRequest: Request) => Request;
+  transformResult?: (result: Result) => Result;
+};
+
+interface IDelegateToSchemaOptions<TContext = {
+  [key: string]: any;
+}> {
+  schema: GraphQLSchema;
+  operation: Operation;
+  fieldName: string;
+  args?: {
+      [key: string]: any;
+  };
+  context: TContext;
+  info: IGraphQLToolsResolveInfo;
+  transforms?: Array<Transform>;
+  skipValidation?: boolean;
+}
+
+type Operation = 'query' | 'mutation' | 'subscription';
+
+type Result = ExecutionResult & {
+  extensions?: Record<string, any>;
+};
+
+interface IGraphQLToolsResolveInfo extends GraphQLResolveInfo {
+  mergeInfo?: MergeInfo;
+}
\ No newline at end of file
diff --git a/lib/routes.js b/lib/routes.js
index bd94aae..122abbc 100644
--- a/lib/routes.js
+++ b/lib/routes.js
@@ -256,7 +256,7 @@ module.exports = async function (app, opts) {
 
       app.get('/graphiql/config.js', (req, reply) => {
         reply
-          .header('Content-Type', 'applicatin/javascript')
+          .header('Content-Type', 'application/javascript')
           .send(`window.GRAPHQL_ENDPOINT = '${graphqlPath}'`)
       })
     }


Test patch:
diff --git a/test/gateway/methods.js b/test/gateway/methods.js
index a34fe6c..6949b07 100644
--- a/test/gateway/methods.js
+++ b/test/gateway/methods.js
@@ -6,7 +6,9 @@ const GQL = require('../..')
 
 async function createService (t, schema, resolvers = {}) {
   const service = Fastify()
-  t.tearDown(() => service.close())
+  t.tearDown(() => {
+    service.close()
+  })
   service.register(GQL, {
     schema,
     resolvers,
@@ -30,7 +32,9 @@ test('calling defineLoaders throws an error in gateway mode', async (t) => {
   `)
 
   const app = Fastify()
-  t.tearDown(() => app.close())
+  t.tearDown(() => {
+    app.close()
+  })
 
   app.register(GQL, {
     gateway: {
@@ -67,7 +71,9 @@ test('calling defineResolvers throws an error in gateway mode', async (t) => {
   `)
 
   const app = Fastify()
-  t.tearDown(() => app.close())
+  t.tearDown(() => {
+    app.close()
+  })
 
   app.register(GQL, {
     gateway: {
@@ -104,7 +110,9 @@ test('calling replaceSchema throws an error in gateway mode', async (t) => {
   `)
 
   const app = Fastify()
-  t.tearDown(() => app.close())
+  t.tearDown(() => {
+    app.close()
+  })
 
   app.register(GQL, {
     gateway: {
@@ -141,7 +149,9 @@ test('calling extendSchema throws an error in gateway mode', async (t) => {
   `)
 
   const app = Fastify()
-  t.tearDown(() => app.close())
+  t.tearDown(() => {
+    app.close()
+  })
 
   app.register(GQL, {
     gateway: {
@@ -162,5 +172,6 @@ test('calling extendSchema throws an error in gateway mode', async (t) => {
     `)
   } catch (err) {
     t.is(err.message, 'Calling extendSchema method is not allowed when plugin is running in gateway mode is not allowed')
+    t.end()
   }
 })
diff --git a/test/gateway/request.js b/test/gateway/request.js
index 2edfdd7..5844f59 100644
--- a/test/gateway/request.js
+++ b/test/gateway/request.js
@@ -25,12 +25,15 @@ test('sendRequest method rejects when response is not valid json', async (t) =>
   app.post('/', async (request, reply) => {
     return 'response'
   })
-  t.tearDown(() => app.close())
 
   await app.listen(0)
 
   const url = new URL(`http://localhost:${app.server.address().port}`)
-  const { request } = buildRequest({})
+  const { request, close } = buildRequest({})
+  t.tearDown(() => {
+    close()
+    app.close()
+  })
   t.rejects(sendRequest(request, url)({
     method: 'POST',
     body: JSON.stringify({
diff --git a/test/gateway/schema.js b/test/gateway/schema.js
index a622b5e..a2f14ab 100644
--- a/test/gateway/schema.js
+++ b/test/gateway/schema.js
@@ -6,7 +6,9 @@ const GQL = require('../..')
 
 async function createService (t, schema, resolvers = {}) {
   const service = Fastify()
-  t.tearDown(() => service.close())
+  t.tearDown(() => {
+    service.close()
+  })
   service.register(GQL, {
     schema,
     resolvers,
@@ -136,7 +138,9 @@ test('It builds the gateway schema correctly', async (t) => {
   })
 
   const gateway = Fastify()
-  t.tearDown(() => gateway.close())
+  t.tearDown(() => {
+    gateway.close()
+  })
   gateway.register(GQL, {
     gateway: {
       services: [{
diff --git a/test/routes.js b/test/routes.js
index 2b18823..da3d9d7 100644
--- a/test/routes.js
+++ b/test/routes.js
@@ -1393,6 +1393,7 @@ test('if ide is playground, serve init.js with the correct endpoint', async (t)
     url: '/playground/init.js'
   })
   t.strictEqual(res.statusCode, 200)
+  t.strictEqual(res.headers['content-type'], 'application/javascript')
   t.matchSnapshot(res.body)
 })
 
@@ -1408,6 +1409,7 @@ test('if ide is graphiql, serve config.js with the correct endpoint', async (t)
     url: '/graphiql/config.js'
   })
   t.strictEqual(res.statusCode, 200)
+  t.strictEqual(res.headers['content-type'], 'application/javascript')
   t.matchSnapshot(res.body)
 })