-
-
Notifications
You must be signed in to change notification settings - Fork 796
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[deploy_website] enhance(schema): add some options to improve schema …
…creation performance (#2280) * enhance(schema): add some options to improve schema creation performance * Fix lint and build issues
- Loading branch information
Showing
14 changed files
with
139 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
'@graphql-tools/schema': minor | ||
'@graphql-tools/stitch': minor | ||
'@graphql-tools/utils': minor | ||
--- | ||
|
||
enhance(schema): add some options to improve schema creation performance |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,43 @@ | ||
import { DocumentNode, DefinitionNode, Kind } from 'graphql'; | ||
|
||
export function extractExtensionDefinitions(ast: DocumentNode) { | ||
const extensionDefs = ast.definitions.filter( | ||
(def: DefinitionNode) => | ||
def.kind === Kind.OBJECT_TYPE_EXTENSION || | ||
def.kind === Kind.INTERFACE_TYPE_EXTENSION || | ||
def.kind === Kind.INPUT_OBJECT_TYPE_EXTENSION || | ||
def.kind === Kind.UNION_TYPE_EXTENSION || | ||
def.kind === Kind.ENUM_TYPE_EXTENSION || | ||
def.kind === Kind.SCALAR_TYPE_EXTENSION || | ||
def.kind === Kind.SCHEMA_EXTENSION | ||
); | ||
const isExtensionNode = (def: DefinitionNode) => | ||
def.kind === Kind.OBJECT_TYPE_EXTENSION || | ||
def.kind === Kind.INTERFACE_TYPE_EXTENSION || | ||
def.kind === Kind.INPUT_OBJECT_TYPE_EXTENSION || | ||
def.kind === Kind.UNION_TYPE_EXTENSION || | ||
def.kind === Kind.ENUM_TYPE_EXTENSION || | ||
def.kind === Kind.SCALAR_TYPE_EXTENSION || | ||
def.kind === Kind.SCHEMA_EXTENSION; | ||
|
||
export function filterAndExtractExtensionDefinitions(ast: DocumentNode) { | ||
const extensionDefs: DefinitionNode[] = []; | ||
const typesDefs: DefinitionNode[] = []; | ||
ast.definitions.forEach(def => { | ||
if (isExtensionNode(def)) { | ||
extensionDefs.push(def); | ||
} else { | ||
typesDefs.push(def); | ||
} | ||
}); | ||
|
||
return { | ||
...ast, | ||
definitions: extensionDefs, | ||
typesAst: { | ||
...ast, | ||
definitions: typesDefs, | ||
}, | ||
extensionsAst: { | ||
...ast, | ||
definitions: extensionDefs, | ||
}, | ||
}; | ||
} | ||
|
||
export function filterExtensionDefinitions(ast: DocumentNode) { | ||
const extensionDefs = ast.definitions.filter( | ||
(def: DefinitionNode) => | ||
def.kind !== Kind.OBJECT_TYPE_EXTENSION && | ||
def.kind !== Kind.INTERFACE_TYPE_EXTENSION && | ||
def.kind !== Kind.INPUT_OBJECT_TYPE_EXTENSION && | ||
def.kind !== Kind.UNION_TYPE_EXTENSION && | ||
def.kind !== Kind.ENUM_TYPE_EXTENSION && | ||
def.kind !== Kind.SCALAR_TYPE_EXTENSION && | ||
def.kind !== Kind.SCHEMA_EXTENSION | ||
); | ||
const { typesAst } = filterAndExtractExtensionDefinitions(ast); | ||
return typesAst; | ||
} | ||
|
||
return { | ||
...ast, | ||
definitions: extensionDefs, | ||
}; | ||
export function extractExtensionDefinitions(ast: DocumentNode) { | ||
const { extensionsAst } = filterAndExtractExtensionDefinitions(ast); | ||
return extensionsAst; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { ASTNode, DocumentNode } from 'graphql'; | ||
|
||
export function isDocumentNode(object: any): object is DocumentNode { | ||
return (object as ASTNode).kind !== undefined; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.