Skip to content

Commit 14865af

Browse files
author
Fabian Schneider
committed
🐛 Build client schema for diffing for local schemas
1 parent a1bb0bf commit 14865af

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"types": "dist/index.d.ts",
77
"scripts": {
88
"build": "tsc",
9+
"dev": "ts-node --files src/cli",
910
"prepack": "npm run build",
1011
"test": "jest",
1112
"lint:fix": "prettier --parser typescript --single-quote --write src/**"

src/__tests__/diff.test.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import nock from 'nock';
22
import path from 'path';
33
import { getDiff } from '../diff';
4-
import { introspectionQuery } from 'graphql';
4+
import { getIntrospectionQuery } from 'graphql';
55
import introspectionResponse from './fixtures/introspectionResponse.json';
66

77
describe('getDiff', () => {
88
describe('remote schema fetching', () => {
99
const testRemoteSchemaLocation = 'http://test/graphql';
10+
const introspectionQuery = getIntrospectionQuery({ descriptions: false });
1011

1112
it('fetches remote schema successfully', async () => {
1213
nock(testRemoteSchemaLocation)

src/diff.ts

+12-6
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ import {
33
findBreakingChanges,
44
findDangerousChanges,
55
GraphQLSchema,
6-
introspectionQuery,
76
buildClientSchema,
87
buildSchema,
98
DangerousChange,
10-
BreakingChange
9+
BreakingChange,
10+
introspectionFromSchema,
11+
getIntrospectionQuery
1112
} from 'graphql';
1213
import fs from 'fs';
1314
import isGlob from 'is-glob';
@@ -23,6 +24,7 @@ async function fetchRemoteSchema(
2324
endpoint: string,
2425
headers?: Headers
2526
): Promise<GraphQLSchema> {
27+
const introspectionQuery = getIntrospectionQuery({ descriptions: false });
2628
const res = await fetch(endpoint, {
2729
method: 'POST',
2830
headers: {
@@ -46,19 +48,23 @@ async function fetchRemoteSchema(
4648
}
4749

4850
function readLocalSchema(schemaPath: string): GraphQLSchema {
51+
let schemaString: string;
52+
4953
if (isGlob(schemaPath)) {
5054
const typesArray = fileLoader(schemaPath);
5155

5256
if (typesArray.length === 0) {
5357
throw new Error(`No types found with glob pattern '${schemaPath}'`);
5458
}
5559

56-
const mergedSchema = mergeTypes(typesArray, { all: true });
57-
return buildSchema(mergedSchema);
60+
schemaString = mergeTypes(typesArray, { all: true });
5861
} else {
59-
const schemaString = fs.readFileSync(schemaPath, 'utf8');
60-
return buildSchema(schemaString);
62+
schemaString = fs.readFileSync(schemaPath, 'utf8');
6163
}
64+
65+
const schema = buildSchema(schemaString);
66+
const introspection = introspectionFromSchema(schema, { descriptions: false })
67+
return buildClientSchema(introspection);
6268
}
6369

6470
async function getSchema(

0 commit comments

Comments
 (0)