diff --git a/packages/directive-headers/src/index.ts b/packages/directive-headers/src/index.ts index cab6ce1..42d1433 100644 --- a/packages/directive-headers/src/index.ts +++ b/packages/directive-headers/src/index.ts @@ -56,3 +56,15 @@ export default class HeadersDirectiveTransform implements MeshTransform { }) } } + +export const headersDirectiveTypeDef: string = /* GraphQL */ ` + input Header { + key: String + value: String + } + + """ + This directive is used to add headers to the request. + """ + directive @headers(input: [Header]) on FIELD +` diff --git a/packages/directive-no-auth/src/index.ts b/packages/directive-no-auth/src/index.ts index 51d4808..c6b84ca 100644 --- a/packages/directive-no-auth/src/index.ts +++ b/packages/directive-no-auth/src/index.ts @@ -50,3 +50,10 @@ export default class NoAuthDirectiveTransform implements MeshTransform { }) } } + +export const noAuthDirectiveTypeDef: string = /* GraphQL */ ` + """ + This directive is used to disable the authorization header for the request + """ + directive @noAuth on FIELD +` diff --git a/packages/directive-spl/src/index.ts b/packages/directive-spl/src/index.ts index 400455d..4d26017 100644 --- a/packages/directive-spl/src/index.ts +++ b/packages/directive-spl/src/index.ts @@ -52,3 +52,10 @@ export default class SplDirectiveTransform implements MeshTransform { }) } } + +export const splDirectiveTypeDef: string = /* GraphQL */ ` + """ + This is a very small, lightweight, straightforward and non-evaluated expression language to sort, filter and paginate arrays of maps. + """ + directive @SPL(query: String) on FIELD +` diff --git a/packages/directive-spl/vite.config.ts b/packages/directive-spl/vite.config.ts index 2abcb3e..0324084 100644 --- a/packages/directive-spl/vite.config.ts +++ b/packages/directive-spl/vite.config.ts @@ -1,16 +1,4 @@ /// // Configure Vitest (https://vitest.dev/config/) -import { resolve } from 'path' import { defineConfig } from 'vite' -import dts from 'vite-plugin-dts' -// https://vitejs.dev/guide/build.html#library-mode -export default defineConfig({ - build: { - lib: { - entry: resolve(__dirname, 'src/index.ts'), - name: 'my-lib', - fileName: 'my-lib' - } - }, - plugins: [dts()] -}) +export default defineConfig({}) diff --git a/packages/graphql-mesh/.meshrc.ts b/packages/graphql-mesh/.meshrc.ts index 76aa748..2784d42 100644 --- a/packages/graphql-mesh/.meshrc.ts +++ b/packages/graphql-mesh/.meshrc.ts @@ -1,5 +1,8 @@ import { YamlConfig } from '@graphql-mesh/types' import ConfigFromSwaggers from './utils/ConfigFromSwaggers' +import { splDirectiveTypeDef } from 'directive-spl' +import { headersDirectiveTypeDef } from 'directive-headers' +import { noAuthDirectiveTypeDef } from 'directive-no-auth' const configFromSwaggers = new ConfigFromSwaggers() const { defaultConfig, additionalTypeDefs, sources } = @@ -19,9 +22,13 @@ const config = { ...(defaultConfig.transforms || []) ].filter(Boolean), sources: [...sources], - additionalTypeDefs: [defaultConfig.additionalTypeDefs || '', ...additionalTypeDefs].filter( - Boolean - ), + additionalTypeDefs: [ + splDirectiveTypeDef, + headersDirectiveTypeDef, + noAuthDirectiveTypeDef, + additionalTypeDefs, + defaultConfig.additionalTypeDefs || '' + ].filter(Boolean), additionalResolvers: [ ...(defaultConfig.additionalResolvers || []), './utils/additionalResolvers.ts' diff --git a/packages/graphql-mesh/local-pkg/directive-headers-1.0.0.tgz b/packages/graphql-mesh/local-pkg/directive-headers-1.0.0.tgz index 4618084..e0ed99a 100644 Binary files a/packages/graphql-mesh/local-pkg/directive-headers-1.0.0.tgz and b/packages/graphql-mesh/local-pkg/directive-headers-1.0.0.tgz differ diff --git a/packages/graphql-mesh/local-pkg/directive-no-auth-1.0.0.tgz b/packages/graphql-mesh/local-pkg/directive-no-auth-1.0.0.tgz index 7667a24..23c6179 100644 Binary files a/packages/graphql-mesh/local-pkg/directive-no-auth-1.0.0.tgz and b/packages/graphql-mesh/local-pkg/directive-no-auth-1.0.0.tgz differ diff --git a/packages/graphql-mesh/local-pkg/directive-spl-1.0.0.tgz b/packages/graphql-mesh/local-pkg/directive-spl-1.0.0.tgz index 4c91b36..eb6d3a5 100644 Binary files a/packages/graphql-mesh/local-pkg/directive-spl-1.0.0.tgz and b/packages/graphql-mesh/local-pkg/directive-spl-1.0.0.tgz differ diff --git a/packages/graphql-mesh/local-pkg/inject-additional-transforms-1.0.0.tgz b/packages/graphql-mesh/local-pkg/inject-additional-transforms-1.0.0.tgz index 0c456c0..93b007f 100644 Binary files a/packages/graphql-mesh/local-pkg/inject-additional-transforms-1.0.0.tgz and b/packages/graphql-mesh/local-pkg/inject-additional-transforms-1.0.0.tgz differ diff --git a/packages/graphql-mesh/utils/ConfigFromSwaggers.ts b/packages/graphql-mesh/utils/ConfigFromSwaggers.ts index 73f7f22..d205717 100644 --- a/packages/graphql-mesh/utils/ConfigFromSwaggers.ts +++ b/packages/graphql-mesh/utils/ConfigFromSwaggers.ts @@ -5,7 +5,6 @@ import { getConfig, getSourceName, getSourceOpenapiEnpoint } from './config' import { getAvailableTypes } from './swaggers' import { mergeObjects } from './helpers' import { generateTypeDefsAndResolversFromSwagger } from './swaggers' -import { directiveTypeDefs } from './directive-typedefs' export default class ConfigFromSwaggers { swaggers: SwaggerName[] = [] @@ -94,7 +93,7 @@ export default class ConfigFromSwaggers { ignoreErrorResponses: true, operationHeaders: { Authorization: `{context.headers["authorization"]}`, - ...(this.config.sources.find((item) => source.includes(item.name))?.handler?.openapi + ...(this.config.sources?.find((item) => source.includes(item.name))?.handler?.openapi ?.operationHeaders || {}) } } @@ -122,7 +121,7 @@ export default class ConfigFromSwaggers { getMeshConfigFromSwaggers(): { defaultConfig: any - additionalTypeDefs: string[] + additionalTypeDefs: string additionalResolvers: any sources: any[] } { @@ -130,7 +129,7 @@ export default class ConfigFromSwaggers { return { defaultConfig: this.config, - additionalTypeDefs: [typeDefs, directiveTypeDefs].filter(Boolean), + additionalTypeDefs: typeDefs, additionalResolvers: resolvers, sources: [...this.getOpenApiSources(), ...this.getOtherSources()] } diff --git a/packages/graphql-mesh/utils/directive-typedefs/index.ts b/packages/graphql-mesh/utils/directive-typedefs/index.ts deleted file mode 100644 index 6c92b9a..0000000 --- a/packages/graphql-mesh/utils/directive-typedefs/index.ts +++ /dev/null @@ -1,26 +0,0 @@ -export const directiveTypeDefs = /* GraphQL */ ` - """ - This is a very small, lightweight, straightforward and non-evaluated expression language to sort, filter and paginate arrays of maps. - """ - directive @SPL(query: String) on FIELD - - """ - This directive is used to disable authentication for a specific operation. - """ - directive @noAuth on FIELD - - type LinkItem { - rel: String - href: String - } - - input Header { - key: String - value: String - } - - """ - This directive is used to add headers to the request. - """ - directive @headers(input: [Header]) on FIELD -` diff --git a/packages/graphql-mesh/utils/swaggers/index.ts b/packages/graphql-mesh/utils/swaggers/index.ts index 5bc1a04..c88c721 100644 --- a/packages/graphql-mesh/utils/swaggers/index.ts +++ b/packages/graphql-mesh/utils/swaggers/index.ts @@ -30,7 +30,15 @@ export const generateTypeDefsAndResolversFromSwagger = ( } } + const linkItemTypeDef = /* GraphQL */ ` + type LinkItem { + rel: String + href: String + } + ` + let typeDefs = '' + typeDefs += linkItemTypeDef const resolvers: Resolvers = {}