diff --git a/dev-test/gql-tag-operations-urql/gql/index.d.ts b/dev-test/gql-tag-operations-urql/gql/index.d.ts index 985f0834eb5..fed8bf093b2 100644 --- a/dev-test/gql-tag-operations-urql/gql/index.d.ts +++ b/dev-test/gql-tag-operations-urql/gql/index.d.ts @@ -5,15 +5,12 @@ declare module '@urql/core' { export function gql( source: '\n query Foo {\n Tweets {\n id\n }\n }\n' ): typeof import('./graphql').FooDocument; - export function gql( source: '\n fragment Lel on Tweet {\n id\n body\n }\n' ): typeof import('./graphql').LelFragmentDoc; - export function gql( source: '\n query Bar {\n Tweets {\n ...Lel\n }\n }\n' ): typeof import('./graphql').BarDocument; - export function gql(source: string): unknown; export type DocumentType> = TDocumentNode extends DocumentNode< diff --git a/packages/plugins/typescript/gql-tag-operations/src/index.ts b/packages/plugins/typescript/gql-tag-operations/src/index.ts index df6a58da846..f1ecd74aea7 100644 --- a/packages/plugins/typescript/gql-tag-operations/src/index.ts +++ b/packages/plugins/typescript/gql-tag-operations/src/index.ts @@ -19,7 +19,7 @@ export type DocumentType> = TDocume > ? TType : never; -`; +`.split(`\n`); export const plugin: PluginFunction<{ sourcesWithOperations: Array; @@ -42,7 +42,8 @@ export const plugin: PluginFunction<{ `export function gql(source: string) {\n`, ` return (documents as any)[source] ?? {};\n`, `}\n`, - documentTypePartial, + `\n`, + ...documentTypePartial, ].join(``); } @@ -53,11 +54,11 @@ export const plugin: PluginFunction<{ `\n`, ...getGqlOverloadChunk(config.sourcesWithOperations, 'augmented'), `export function gql(source: string): unknown;\n`, - documentTypePartial, + `\n`, + ...documentTypePartial, ] .map(line => (line === `\n` ? line : ` ${line}`)) - .join(`\n`), - + .join(``), `}`, ].join(`\n`); }; @@ -90,7 +91,7 @@ function getGqlOverloadChunk(sourcesWithOperations: Array, const returnType = mode === 'lookup' ? `(typeof documents)[${JSON.stringify(originalString)}]` - : `typeof import('./graphql').${operations[0].initialName};`; + : `typeof import('./graphql').${operations[0].initialName}`; lines.push(`export function gql(source: ${JSON.stringify(originalString)}): ${returnType};\n`); }