-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): added support for generated fragments and it's use inside…
… documents
- Loading branch information
1 parent
e2fb340
commit fbd268c
Showing
7 changed files
with
66 additions
and
15 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,3 @@ | ||
{ | ||
"strategy": "SINGLE_FILE" | ||
} |
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,37 @@ | ||
import {GraphQLSchema} from "graphql/type/schema"; | ||
import {FragmentDefinitionNode} from "graphql/language/ast"; | ||
import {Model, CodegenDocument} from "./interfaces"; | ||
import pascalCase = require("pascal-case"); | ||
import {buildInnerModelsArray} from "./operation-handler"; | ||
import {typeFromAST} from "graphql/utilities/typeFromAST"; | ||
|
||
export const handleFragment = (schema: GraphQLSchema, fragmentNode: FragmentDefinitionNode): CodegenDocument => { | ||
const rawName = fragmentNode.name.value; | ||
const fragmentName = pascalCase(rawName); | ||
|
||
let result: CodegenDocument = { | ||
name: fragmentName, | ||
rawName: rawName, | ||
isQuery: false, | ||
isSubscription: false, | ||
isMutation: false, | ||
isFragment: true, | ||
innerTypes: [], | ||
hasInnerTypes: false, | ||
variables: [], | ||
hasVariables: false | ||
}; | ||
|
||
let appendTo: Model = { | ||
name: 'Fragment', | ||
fields: [], | ||
isObject: true, | ||
isFragment: true | ||
}; | ||
|
||
const root = typeFromAST(schema, fragmentNode.typeCondition); | ||
result.innerTypes = [appendTo, ...buildInnerModelsArray(schema, root, fragmentNode.selectionSet, appendTo)]; | ||
result.hasInnerTypes = result.innerTypes.length > 0; | ||
|
||
return result; | ||
}; |
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