diff --git a/examples/apollo-watch-fragments/src/__generated__/TodoList_todosWatchNodeQuery.graphql.ts b/examples/apollo-watch-fragments/src/__generated__/TodoList_todosWatchNodeQuery.graphql.ts index 91862751..f84d6ef5 100644 --- a/examples/apollo-watch-fragments/src/__generated__/TodoList_todosWatchNodeQuery.graphql.ts +++ b/examples/apollo-watch-fragments/src/__generated__/TodoList_todosWatchNodeQuery.graphql.ts @@ -25,35 +25,6 @@ query TodoList_todosWatchNodeQuery($id: ID!) { } } -fragment TodoList_todosFragment on TodosConnection { - edges { - node { - id - isCompleted - ...Todo_todoFragment - } - } - id -} - -fragment Todo_todoFragment on Todo { - id - description - isCompleted -} - -*/ -export const executionQueryDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"TodoList_todosWatchNodeQuery"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"id"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"ID"}}},"directives":[]}],"directives":[],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"node"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"id"},"value":{"kind":"Variable","name":{"kind":"Name","value":"id"}}}],"directives":[],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"__typename"},"arguments":[],"directives":[]},{"kind":"FragmentSpread","name":{"kind":"Name","value":"TodoList_todosFragment"},"directives":[]},{"kind":"Field","name":{"kind":"Name","value":"id"},"arguments":[],"directives":[]}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"TodoList_todosFragment"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"TodosConnection"}},"directives":[],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"edges"},"arguments":[],"directives":[],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"node"},"arguments":[],"directives":[],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"},"arguments":[],"directives":[]},{"kind":"Field","name":{"kind":"Name","value":"isCompleted"},"arguments":[],"directives":[]},{"kind":"FragmentSpread","name":{"kind":"Name","value":"Todo_todoFragment"},"directives":[]}]}}]}},{"kind":"Field","name":{"kind":"Name","value":"id"},"arguments":[],"directives":[]}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"Todo_todoFragment"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"Todo"}},"directives":[],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"},"arguments":[],"directives":[]},{"kind":"Field","name":{"kind":"Name","value":"description"},"arguments":[],"directives":[]},{"kind":"Field","name":{"kind":"Name","value":"isCompleted"},"arguments":[],"directives":[]}]}}]}; - -/* -query TodoList_todosWatchNodeQuery($id: ID!) { - node(id: $id) { - __typename - ...TodoList_todosFragment - id - } -} - fragment TodoList_todosFragment on TodosConnection { edges { node { diff --git a/examples/apollo-watch-fragments/src/__generated__/Todo_todoWatchNodeQuery.graphql.ts b/examples/apollo-watch-fragments/src/__generated__/Todo_todoWatchNodeQuery.graphql.ts index e101f012..a3bfc1ab 100644 --- a/examples/apollo-watch-fragments/src/__generated__/Todo_todoWatchNodeQuery.graphql.ts +++ b/examples/apollo-watch-fragments/src/__generated__/Todo_todoWatchNodeQuery.graphql.ts @@ -31,23 +31,5 @@ fragment Todo_todoFragment on Todo { isCompleted } -*/ -export const executionQueryDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"Todo_todoWatchNodeQuery"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"id"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"ID"}}},"directives":[]}],"directives":[],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"node"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"id"},"value":{"kind":"Variable","name":{"kind":"Name","value":"id"}}}],"directives":[],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"__typename"},"arguments":[],"directives":[]},{"kind":"FragmentSpread","name":{"kind":"Name","value":"Todo_todoFragment"},"directives":[]},{"kind":"Field","name":{"kind":"Name","value":"id"},"arguments":[],"directives":[]}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"Todo_todoFragment"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"Todo"}},"directives":[],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"},"arguments":[],"directives":[]},{"kind":"Field","name":{"kind":"Name","value":"description"},"arguments":[],"directives":[]},{"kind":"Field","name":{"kind":"Name","value":"isCompleted"},"arguments":[],"directives":[]}]}}]}; - -/* -query Todo_todoWatchNodeQuery($id: ID!) { - node(id: $id) { - __typename - ...Todo_todoFragment - id - } -} - -fragment Todo_todoFragment on Todo { - id - description - isCompleted -} - */ export const watchQueryDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"Todo_todoWatchNodeQuery"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"id"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"ID"}}},"directives":[]}],"directives":[],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"node"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"id"},"value":{"kind":"Variable","name":{"kind":"Name","value":"id"}}}],"directives":[],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"__typename"},"arguments":[],"directives":[]},{"kind":"FragmentSpread","name":{"kind":"Name","value":"Todo_todoFragment"},"directives":[]},{"kind":"Field","name":{"kind":"Name","value":"id"},"arguments":[],"directives":[]}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"Todo_todoFragment"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"Todo"}},"directives":[],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"},"arguments":[],"directives":[]},{"kind":"Field","name":{"kind":"Name","value":"description"},"arguments":[],"directives":[]},{"kind":"Field","name":{"kind":"Name","value":"isCompleted"},"arguments":[],"directives":[]}]}}]}; \ No newline at end of file diff --git a/packages/relay-compiler-language-graphitation/src/formatModule.ts b/packages/relay-compiler-language-graphitation/src/formatModule.ts index a9e94012..653b2995 100644 --- a/packages/relay-compiler-language-graphitation/src/formatModule.ts +++ b/packages/relay-compiler-language-graphitation/src/formatModule.ts @@ -22,12 +22,19 @@ function emitDocument(document: DocumentNode, exportName: string) { export const ${exportName} = ${JSON.stringify(document)};`; } -export const formatModule: FormatModule = ({ docText, hash, typeText }) => { +export const formatModule: FormatModule = ({ + docText, + hash, + moduleName, + typeText, +}) => { let append = ""; if (docText) { const originalDocument = parse(docText, { noLocation: true }); - append += emitDocument(originalDocument, "executionQueryDocument"); - append += "\n"; + if (!moduleName.endsWith("WatchNodeQuery.graphql")) { + append += emitDocument(originalDocument, "executionQueryDocument"); + append += "\n"; + } const reducedDocument = reduceNodeWatchQuery(schema, originalDocument); append += emitDocument(reducedDocument, "watchQueryDocument"); }