Add GraphQL fragment support (#2005)

master
Sashko Stubailo 2017-06-06 12:35:40 -07:00 committed by Christopher Chedeau
parent d4774edd03
commit c441f87fc0
4 changed files with 76 additions and 0 deletions

View File

@ -48,6 +48,16 @@ function genericPrint(path, options, print) {
path.call(print, "selectionSet")
]);
}
case "FragmentDefinition": {
return concat([
"fragment ",
path.call(print, "name"),
" on ",
path.call(print, "typeCondition"),
" ",
path.call(print, "selectionSet")
]);
}
case "SelectionSet": {
return concat([
"{",
@ -141,6 +151,21 @@ function genericPrint(path, options, print) {
]);
}
case "FragmentSpread": {
return concat(["...", path.call(print, "name")]);
}
case "InlineFragment": {
return concat([
"...",
n.typeCondition
? concat([" on ", path.call(print, "typeCondition")])
: "",
" ",
path.call(print, "selectionSet")
]);
}
default:
throw new Error("unknown graphql type: " + JSON.stringify(n.kind));
}

View File

@ -0,0 +1,35 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`fragments.graphql 1`] = `
{
field
... XYZ
... on TheType {
...AFragment
... {
noTypeCondition
}
}
}
fragment XYZ on ABC {
field
...AFragment
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
{
field
...XYZ
... on TheType {
...AFragment
... {
noTypeCondition
}
}
}
fragment XYZ on ABC {
field
...AFragment
}
`;

View File

@ -0,0 +1,15 @@
{
field
... XYZ
... on TheType {
...AFragment
... {
noTypeCondition
}
}
}
fragment XYZ on ABC {
field
...AFragment
}

View File

@ -0,0 +1 @@
run_spec(__dirname, { parser: "graphql" });