Skip to content

Commit

Permalink
refactor: change style of generated artifact
Browse files Browse the repository at this point in the history
  • Loading branch information
n1ru4l committed Aug 17, 2021
1 parent ed35c08 commit fcee8d5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
3 changes: 0 additions & 3 deletions dev-test/gql-tag-operations-urql/gql/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<any, any>> = TDocumentNode extends DocumentNode<
Expand Down
13 changes: 7 additions & 6 deletions packages/plugins/typescript/gql-tag-operations/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export type DocumentType<TDocumentNode extends DocumentNode<any, any>> = TDocume
>
? TType
: never;
`;
`.split(`\n`);

export const plugin: PluginFunction<{
sourcesWithOperations: Array<SourceWithOperations>;
Expand All @@ -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(``);
}

Expand All @@ -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`);
};
Expand Down Expand Up @@ -90,7 +91,7 @@ function getGqlOverloadChunk(sourcesWithOperations: Array<SourceWithOperations>,
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`);
}

Expand Down

0 comments on commit fcee8d5

Please sign in to comment.