Add GraphQL fragment support (#2005)
parent
d4774edd03
commit
c441f87fc0
|
@ -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));
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
`;
|
|
@ -0,0 +1,15 @@
|
|||
{
|
||||
field
|
||||
... XYZ
|
||||
... on TheType {
|
||||
...AFragment
|
||||
... {
|
||||
noTypeCondition
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fragment XYZ on ABC {
|
||||
field
|
||||
...AFragment
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
run_spec(__dirname, { parser: "graphql" });
|
Loading…
Reference in New Issue