@graphql-codegen/gql-tag-operations
Advanced tools
Comparing version 1.1.4-alpha-592215161.0 to 1.2.0-alpha-3a2ddbb1c.0
@@ -14,2 +14,3 @@ import { PluginFunction } from '@graphql-codegen/plugin-helpers'; | ||
sourcesWithOperations: Array<SourceWithOperations>; | ||
augmentedModuleName?: string; | ||
}>; |
54
index.js
@@ -12,21 +12,38 @@ 'use strict'; | ||
: never; | ||
`; | ||
const plugin = (_, __, { sourcesWithOperations }) => { | ||
if (!sourcesWithOperations) { | ||
`.split(`\n`); | ||
const plugin = (_, __, config) => { | ||
if (!config.sourcesWithOperations) { | ||
return ''; | ||
} | ||
if (config.augmentedModuleName == null) { | ||
return [ | ||
`import * as graphql from './graphql';\n`, | ||
`import { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/core';\n`, | ||
`\n`, | ||
...getDocumentRegistryChunk(config.sourcesWithOperations), | ||
`\n`, | ||
...getGqlOverloadChunk(config.sourcesWithOperations, 'lookup'), | ||
`\n`, | ||
`export function gql(source: string): unknown;\n`, | ||
`export function gql(source: string) {\n`, | ||
` return (documents as any)[source] ?? {};\n`, | ||
`}\n`, | ||
`\n`, | ||
...documentTypePartial, | ||
].join(``); | ||
} | ||
return [ | ||
`import * as graphql from './graphql';\n`, | ||
`import { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/core';\n`, | ||
`\n`, | ||
...getDocumentRegistryChunk(sourcesWithOperations), | ||
`\n`, | ||
...getGqlOverloadChunk(sourcesWithOperations), | ||
`\n`, | ||
`export function gql(source: string): unknown;\n`, | ||
`export function gql(source: string) {\n`, | ||
` return (documents as any)[source] ?? {};\n`, | ||
`}\n`, | ||
documentTypePartial, | ||
].join(``); | ||
`declare module "${config.augmentedModuleName}" {`, | ||
[ | ||
`\n`, | ||
...getGqlOverloadChunk(config.sourcesWithOperations, 'augmented'), | ||
`export function gql(source: string): unknown;\n`, | ||
`\n`, | ||
...documentTypePartial, | ||
] | ||
.map(line => (line === `\n` ? line : ` ${line}`)) | ||
.join(``), | ||
`}`, | ||
].join(`\n`); | ||
}; | ||
@@ -44,3 +61,3 @@ function getDocumentRegistryChunk(sourcesWithOperations = []) { | ||
} | ||
function getGqlOverloadChunk(sourcesWithOperations) { | ||
function getGqlOverloadChunk(sourcesWithOperations, mode) { | ||
const lines = []; | ||
@@ -51,3 +68,6 @@ // We intentionally don't use a <T extends keyof typeof documents> generic, because TS | ||
const originalString = rest.source.rawSDL; | ||
lines.push(`export function gql(source: ${JSON.stringify(originalString)}): (typeof documents)[${JSON.stringify(originalString)}];\n`); | ||
const returnType = mode === 'lookup' | ||
? `(typeof documents)[${JSON.stringify(originalString)}]` | ||
: `typeof import('./graphql').${operations[0].initialName}`; | ||
lines.push(`export function gql(source: ${JSON.stringify(originalString)}): ${returnType};\n`); | ||
} | ||
@@ -54,0 +74,0 @@ return lines; |
{ | ||
"name": "@graphql-codegen/gql-tag-operations", | ||
"version": "1.1.4-alpha-592215161.0", | ||
"version": "1.2.0-alpha-3a2ddbb1c.0", | ||
"description": "GraphQL Code Generator plugin for generating a typed gql tag function", | ||
@@ -10,4 +10,4 @@ "peerDependencies": { | ||
"dependencies": { | ||
"@graphql-codegen/plugin-helpers": "2.1.2-alpha-592215161.0", | ||
"@graphql-codegen/visitor-plugin-common": "2.2.1-alpha-592215161.0", | ||
"@graphql-codegen/plugin-helpers": "^2.1.1", | ||
"@graphql-codegen/visitor-plugin-common": "2.2.0", | ||
"@graphql-tools/utils": "^8.1.1", | ||
@@ -14,0 +14,0 @@ "auto-bind": "~4.0.0", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7059
155
+ Added@graphql-codegen/plugin-helpers@2.7.2(transitive)
+ Added@graphql-codegen/visitor-plugin-common@2.2.0(transitive)
+ Added@graphql-tools/utils@8.2.1(transitive)
+ Addedcommon-tags@1.8.2(transitive)
+ Addedtslib@2.4.1(transitive)
- Removed@graphql-codegen/plugin-helpers@2.1.2-alpha-592215161.0(transitive)
- Removed@graphql-codegen/visitor-plugin-common@2.2.1-alpha-592215161.0(transitive)
- Removed@graphql-tools/utils@8.2.2(transitive)
- Removedcommon-tags@1.8.0(transitive)