diff --git a/.changeset/pink-squids-sleep.md b/.changeset/pink-squids-sleep.md new file mode 100644 index 0000000000000..e0b088e8f1070 --- /dev/null +++ b/.changeset/pink-squids-sleep.md @@ -0,0 +1,5 @@ +--- +'@graphql-mesh/transform-naming-convention': patch +--- + +Fix diff --git a/examples/fastify/.meshrc.yml b/examples/fastify/.meshrc.yml index 4b528585e71c1..1ed454c1058f4 100644 --- a/examples/fastify/.meshrc.yml +++ b/examples/fastify/.meshrc.yml @@ -1,3 +1,4 @@ +merger: bare sources: - name: Swapi handler: @@ -5,3 +6,7 @@ sources: source: ./swagger/pets.json endpoint: >- http://localhost:4001 + transforms: + - namingConvention: + mode: bare + fieldNames: camelCase diff --git a/examples/fastify/tests/__snapshots__/fastify.spec.ts.snap b/examples/fastify/tests/__snapshots__/fastify.spec.ts.snap new file mode 100644 index 0000000000000..d68a960d54641 --- /dev/null +++ b/examples/fastify/tests/__snapshots__/fastify.spec.ts.snap @@ -0,0 +1,32 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`fastify should introspect correctly: schema 1`] = ` +"directive @globalOptions(sourceName: String, endpoint: String, operationHeaders: ObjMap, queryStringOptions: ObjMap, queryParams: ObjMap) on OBJECT + +directive @httpOperation(path: String, operationSpecificHeaders: ObjMap, httpMethod: HTTPMethod, isBinary: Boolean, requestBaseBody: ObjMap, queryParamArgMap: ObjMap, queryStringOptionsByParam: ObjMap) on FIELD_DEFINITION + +type Query { + petByPetId( + """ID of pet to return""" + petId: String! + ): Pet +} + +type Pet { + name: String! +} + +scalar ObjMap + +enum HTTPMethod { + GET + HEAD + POST + PUT + DELETE + CONNECT + OPTIONS + TRACE + PATCH +}" +`; diff --git a/examples/fastify/tests/fastify.spec.ts b/examples/fastify/tests/fastify.spec.ts index e26a787382026..51dc6b63ac602 100644 --- a/examples/fastify/tests/fastify.spec.ts +++ b/examples/fastify/tests/fastify.spec.ts @@ -1,3 +1,4 @@ +import { buildClientSchema, getIntrospectionQuery, printSchema } from 'graphql'; import { fetch } from '@whatwg-node/fetch'; import { app } from '../src/app'; import { upstream } from '../src/upstream'; @@ -17,6 +18,21 @@ describe('fastify', () => { await upstream.close(); }); + it('should introspect correctly', async () => { + const response = await fetch('http://localhost:4000/graphql', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ + query: getIntrospectionQuery(), + }), + }); + const json = await response.json(); + const schema = buildClientSchema(json.data); + expect(printSchema(schema)).toMatchSnapshot('schema'); + }); + it('should work', async () => { const response = await fetch('http://localhost:4000/graphql', { method: 'POST', @@ -26,7 +42,7 @@ describe('fastify', () => { body: JSON.stringify({ query: /* GraphQL */ ` { - pet_by_petId(petId: "pet200") { + petByPetId(petId: "pet200") { name } } @@ -35,7 +51,10 @@ describe('fastify', () => { }); const json = await response.json(); - expect(json.data).toEqual({ pet_by_petId: { name: 'Bob' } }); + + expect(json).toEqual({ + data: { petByPetId: { name: 'Bob' } }, + }); }); it('should work too', async () => { @@ -47,7 +66,7 @@ describe('fastify', () => { body: JSON.stringify({ query: /* GraphQL */ ` { - pet_by_petId(petId: "pet500") { + petByPetId(petId: "pet500") { name } } @@ -58,11 +77,11 @@ describe('fastify', () => { const resJson = await response.json(); expect(resJson).toEqual({ - data: { pet_by_petId: null }, + data: { petByPetId: null }, errors: [ { message: 'HTTP Error: 500, Could not invoke operation GET /pet/{args.petId}', - path: ['pet_by_petId'], + path: ['petByPetId'], extensions: { request: { url: 'http://localhost:4001/pet/pet500', method: 'GET' }, responseJson: { error: 'Error' }, diff --git a/packages/handlers/openapi/src/index.ts b/packages/handlers/openapi/src/index.ts index f1f0720404e88..ef301d95242fb 100644 --- a/packages/handlers/openapi/src/index.ts +++ b/packages/handlers/openapi/src/index.ts @@ -1,11 +1,4 @@ -import { - buildSchema, - execute, - ExecutionArgs, - GraphQLSchema, - OperationTypeNode, - subscribe, -} from 'graphql'; +import { buildSchema, GraphQLSchema } from 'graphql'; import { PredefinedProxyOptions, StoreProxy } from '@graphql-mesh/store'; import { stringInterpolator } from '@graphql-mesh/string-interpolation'; import { @@ -20,7 +13,6 @@ import { YamlConfig, } from '@graphql-mesh/types'; import { readFileOrUrl } from '@graphql-mesh/utils'; -import { getOperationASTFromRequest } from '@graphql-tools/utils'; import { loadNonExecutableGraphQLSchemaFromOpenAPI, processDirectives } from '@omnigraph/openapi'; export default class OpenAPIHandler implements MeshHandler { @@ -107,33 +99,15 @@ export default class OpenAPIHandler implements MeshHandler { const nonExecutableSchema = await this.getNonExecutableSchema({ interpolatedSource, }); - const schemaWithDirectives$ = Promise.resolve().then(() => { - this.logger.info(`Processing annotations for the execution layer`); - return processDirectives({ - ...this.config, - schema: nonExecutableSchema, - pubsub: this.pubsub, - logger: this.logger, - globalFetch: fetchFn, - }); + const schema = processDirectives({ + ...this.config, + schema: nonExecutableSchema, + pubsub: this.pubsub, + logger: this.logger, + globalFetch: fetchFn, }); return { - schema: nonExecutableSchema, - executor: async executionRequest => { - const args: ExecutionArgs = { - schema: await schemaWithDirectives$, - document: executionRequest.document, - variableValues: executionRequest.variables, - operationName: executionRequest.operationName, - contextValue: executionRequest.context, - rootValue: executionRequest.rootValue, - }; - const operationAST = getOperationASTFromRequest(executionRequest); - if (operationAST.operation === OperationTypeNode.SUBSCRIPTION) { - return subscribe(args) as any; - } - return execute(args) as any; - }, + schema, }; } } diff --git a/packages/transforms/naming-convention/src/bareNamingConvention.ts b/packages/transforms/naming-convention/src/bareNamingConvention.ts index a1fe83bf67496..5bf3362196d0a 100644 --- a/packages/transforms/naming-convention/src/bareNamingConvention.ts +++ b/packages/transforms/naming-convention/src/bareNamingConvention.ts @@ -273,7 +273,7 @@ function argsFromArgMap(argMap: ArgsMap, args: any) { Object.keys(args).forEach(newArgName => { if (typeof newArgName !== 'string') return; - const argMapVal = argMap[newArgName]; + const argMapVal = argMap[newArgName] || newArgName; const originalArgName = typeof argMapVal === 'string' ? argMapVal : argMapVal.originalName; const val = args[newArgName]; if (Array.isArray(val) && typeof argMapVal !== 'string') { @@ -286,6 +286,5 @@ function argsFromArgMap(argMap: ArgsMap, args: any) { originalArgs[originalArgName] = val; } }); - return originalArgs; }