|
1 | 1 | const http = require('http');
|
2 | 2 | const express = require('express');
|
3 | 3 | const req = require('../lib/request');
|
4 |
| -const fetch = (...args) => import('node-fetch').then(({ default: fetch }) => fetch(...args)); |
5 |
| -const FormData = require('form-data'); |
| 4 | +const { fetch, FormData } = require('@whatwg-node/fetch'); |
6 | 5 | const ws = require('ws');
|
7 | 6 | require('./helper');
|
8 | 7 | const { updateCLP } = require('./support/dev');
|
@@ -30,6 +29,7 @@ const {
|
30 | 29 | GraphQLInputObjectType,
|
31 | 30 | GraphQLSchema,
|
32 | 31 | GraphQLList,
|
| 32 | + GraphQLError, |
33 | 33 | } = require('graphql');
|
34 | 34 | const { ParseServer } = require('../');
|
35 | 35 | const { ParseGraphQLServer } = require('../lib/GraphQL/ParseGraphQLServer');
|
@@ -99,54 +99,6 @@ describe('ParseGraphQLServer', () => {
|
99 | 99 | });
|
100 | 100 | });
|
101 | 101 |
|
102 |
| - describe('_getServer', () => { |
103 |
| - it('should only return new server on schema changes', async () => { |
104 |
| - parseGraphQLServer.server = undefined; |
105 |
| - const server1 = await parseGraphQLServer._getServer(); |
106 |
| - const server2 = await parseGraphQLServer._getServer(); |
107 |
| - expect(server1).toBe(server2); |
108 |
| - |
109 |
| - // Trigger a schema change |
110 |
| - const obj = new Parse.Object('SomeClass'); |
111 |
| - await obj.save(); |
112 |
| - |
113 |
| - const server3 = await parseGraphQLServer._getServer(); |
114 |
| - const server4 = await parseGraphQLServer._getServer(); |
115 |
| - expect(server3).not.toBe(server2); |
116 |
| - expect(server3).toBe(server4); |
117 |
| - }); |
118 |
| - }); |
119 |
| - |
120 |
| - describe('_getGraphQLOptions', () => { |
121 |
| - const req = { |
122 |
| - info: new Object(), |
123 |
| - config: new Object(), |
124 |
| - auth: new Object(), |
125 |
| - }; |
126 |
| - |
127 |
| - it("should return schema and context with req's info, config and auth", async () => { |
128 |
| - const options = await parseGraphQLServer._getGraphQLOptions(); |
129 |
| - expect(options.multipart).toEqual({ |
130 |
| - fileSize: 20971520, |
131 |
| - }); |
132 |
| - expect(options.schema).toEqual(parseGraphQLServer.parseGraphQLSchema.graphQLSchema); |
133 |
| - const contextResponse = options.context({ req }); |
134 |
| - expect(contextResponse.info).toEqual(req.info); |
135 |
| - expect(contextResponse.config).toEqual(req.config); |
136 |
| - expect(contextResponse.auth).toEqual(req.auth); |
137 |
| - }); |
138 |
| - |
139 |
| - it('should load GraphQL schema in every call', async () => { |
140 |
| - const originalLoad = parseGraphQLServer.parseGraphQLSchema.load; |
141 |
| - let counter = 0; |
142 |
| - parseGraphQLServer.parseGraphQLSchema.load = () => ++counter; |
143 |
| - expect((await parseGraphQLServer._getGraphQLOptions(req)).schema).toEqual(1); |
144 |
| - expect((await parseGraphQLServer._getGraphQLOptions(req)).schema).toEqual(2); |
145 |
| - expect((await parseGraphQLServer._getGraphQLOptions(req)).schema).toEqual(3); |
146 |
| - parseGraphQLServer.parseGraphQLSchema.load = originalLoad; |
147 |
| - }); |
148 |
| - }); |
149 |
| - |
150 | 102 | describe('_transformMaxUploadSizeToBytes', () => {
|
151 | 103 | it('should transform to bytes', () => {
|
152 | 104 | expect(parseGraphQLServer._transformMaxUploadSizeToBytes('20mb')).toBe(20971520);
|
@@ -532,41 +484,6 @@ describe('ParseGraphQLServer', () => {
|
532 | 484 | expect(healthResponse.data.health).toBeTruthy();
|
533 | 485 | expect(checked).toBeTruthy();
|
534 | 486 | });
|
535 |
| - |
536 |
| - it('should handle Parse headers', async () => { |
537 |
| - const test = { |
538 |
| - context: ({ req: { info, config, auth } }) => { |
539 |
| - expect(req.info).toBeDefined(); |
540 |
| - expect(req.config).toBeDefined(); |
541 |
| - expect(req.auth).toBeDefined(); |
542 |
| - return { |
543 |
| - info, |
544 |
| - config, |
545 |
| - auth, |
546 |
| - }; |
547 |
| - }, |
548 |
| - }; |
549 |
| - const contextSpy = spyOn(test, 'context'); |
550 |
| - const originalGetGraphQLOptions = parseGraphQLServer._getGraphQLOptions; |
551 |
| - parseGraphQLServer._getGraphQLOptions = async () => { |
552 |
| - return { |
553 |
| - schema: await parseGraphQLServer.parseGraphQLSchema.load(), |
554 |
| - context: test.context, |
555 |
| - }; |
556 |
| - }; |
557 |
| - const health = ( |
558 |
| - await apolloClient.query({ |
559 |
| - query: gql` |
560 |
| - query Health { |
561 |
| - health |
562 |
| - } |
563 |
| - `, |
564 |
| - }) |
565 |
| - ).data.health; |
566 |
| - expect(health).toBeTruthy(); |
567 |
| - expect(contextSpy).toHaveBeenCalledTimes(1); |
568 |
| - parseGraphQLServer._getGraphQLOptions = originalGetGraphQLOptions; |
569 |
| - }); |
570 | 487 | });
|
571 | 488 |
|
572 | 489 | describe('Playground', () => {
|
@@ -10945,7 +10862,7 @@ describe('ParseGraphQLServer', () => {
|
10945 | 10862 | errorQuery: {
|
10946 | 10863 | type: new GraphQLNonNull(GraphQLString),
|
10947 | 10864 | resolve: () => {
|
10948 |
| - throw new Error('A test error'); |
| 10865 | + throw new GraphQLError('A test error'); |
10949 | 10866 | },
|
10950 | 10867 | },
|
10951 | 10868 | customQueryWithAutoTypeReturn: {
|
|
0 commit comments