Skip to content

Commit 8f331aa

Browse files
authored
Small refactor and fixes in printSchemaWithDirectives and improvements in other packages (#2611)
* somework * changeset
1 parent 25f9a85 commit 8f331aa

File tree

13 files changed

+66
-32
lines changed

13 files changed

+66
-32
lines changed

.changeset/heavy-peaches-search.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@graphql-tools/utils': patch
3+
---
4+
5+
fix(utils): fix missing default value of input object type field

.changeset/sweet-humans-draw.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@graphql-tools/utils': minor
3+
---
4+
5+
enhance(utils): Extract getDocumentNodeFromSchema from printSchemaWithDirectives

.changeset/young-chairs-float.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@graphql-tools/load': patch
3+
'@graphql-tools/module-loader': patch
4+
'@graphql-tools/merge': patch
5+
---
6+
7+
enhance(load/module-loader/merge): use getDocumentNodeFromSchema instead of parse and printSchemaWithDirectives together

packages/load/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"graphql-type-json": "0.3.2"
2727
},
2828
"dependencies": {
29-
"@graphql-tools/utils": "^7.0.0",
29+
"@graphql-tools/utils": "^7.3.0",
3030
"@graphql-tools/merge": "^6.2.5",
3131
"globby": "11.0.2",
3232
"import-from": "3.0.0",

packages/load/src/load-typedefs/collect-sources.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { Source, isDocumentString, parseGraphQLSDL, asArray, printSchemaWithDirectives } from '@graphql-tools/utils';
2-
import { isSchema, Kind, parse } from 'graphql';
1+
import { Source, isDocumentString, parseGraphQLSDL, asArray, getDocumentNodeFromSchema } from '@graphql-tools/utils';
2+
import { isSchema, Kind } from 'graphql';
33
import isGlob from 'is-glob';
44
import { LoadTypedefsOptions } from '../load-typedefs';
55
import { loadFile, loadFileSync } from './load-file';
@@ -296,7 +296,7 @@ function addResultOfCustomLoader({
296296
source: {
297297
location: pointer,
298298
schema: result,
299-
document: parse(printSchemaWithDirectives(result)),
299+
document: getDocumentNodeFromSchema(result),
300300
},
301301
pointer,
302302
noCache: true,

packages/loaders/module/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"graphql": "^14.0.0 || ^15.0.0"
2121
},
2222
"dependencies": {
23-
"@graphql-tools/utils": "^7.0.0",
23+
"@graphql-tools/utils": "^7.3.0",
2424
"tslib": "~2.1.0"
2525
},
2626
"publishConfig": {

packages/loaders/module/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { parse, isSchema } from 'graphql';
22
import {
33
UniversalLoader,
44
fixSchemaAst,
5-
printSchemaWithDirectives,
5+
getDocumentNodeFromSchema,
66
SingleFileOptions,
77
Source,
88
} from '@graphql-tools/utils';
@@ -86,7 +86,7 @@ export class ModuleLoader implements UniversalLoader {
8686
return {
8787
schema,
8888
get document() {
89-
return parse(printSchemaWithDirectives(schema, options));
89+
return getDocumentNodeFromSchema(schema);
9090
},
9191
location: pointer,
9292
};

packages/merge/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
},
2525
"dependencies": {
2626
"@graphql-tools/schema": "^7.0.0",
27-
"@graphql-tools/utils": "^7.0.0",
27+
"@graphql-tools/utils": "^7.3.0",
2828
"tslib": "~2.1.0"
2929
},
3030
"publishConfig": {

packages/merge/src/typedefs-mergers/merge-typedefs.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { DefinitionNode, DocumentNode, GraphQLSchema, parse, Source, Kind, isSch
22
import { isSourceTypes, isStringTypes, isSchemaDefinition } from './utils';
33
import { MergedResultMap, mergeGraphQLNodes } from './merge-nodes';
44
import { resetComments, printWithComments } from './comments';
5-
import { createSchemaDefinition, printSchemaWithDirectives } from '@graphql-tools/utils';
5+
import { createSchemaDefinition, getDocumentNodeFromSchema } from '@graphql-tools/utils';
66

77
type Omit<T, K extends keyof any> = Pick<T, Exclude<keyof T, K>>;
88
type CompareFn<T> = (a: T, b: T) => number;
@@ -115,7 +115,7 @@ export function mergeGraphQLTypes(
115115
type = mergeTypeDefs(type);
116116
}
117117
if (isSchema(type)) {
118-
return parse(printSchemaWithDirectives(type));
118+
return getDocumentNodeFromSchema(type);
119119
} else if (isStringTypes(type) || isSourceTypes(type)) {
120120
return parse(type);
121121
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { ASTNode, DocumentNode } from 'graphql';
1+
import { DocumentNode, Kind } from 'graphql';
22

33
export function isDocumentNode(object: any): object is DocumentNode {
4-
return (object as ASTNode).kind !== undefined;
4+
return object && typeof object === 'object' && 'kind' in object && object.kind === Kind.DOCUMENT;
55
}

0 commit comments

Comments
 (0)