Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example of Bare naming convention transform resolver regression #5405

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/pink-squids-sleep.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphql-mesh/transform-naming-convention': patch
---

Fix
5 changes: 5 additions & 0 deletions examples/fastify/.meshrc.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
merger: bare
sources:
- name: Swapi
handler:
openapi:
source: ./swagger/pets.json
endpoint: >-
http://localhost:4001
transforms:
- namingConvention:
mode: bare
fieldNames: camelCase
32 changes: 32 additions & 0 deletions examples/fastify/tests/__snapshots__/fastify.spec.ts.snap
Original file line number Diff line number Diff line change
@@ -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
}"
`;
29 changes: 24 additions & 5 deletions examples/fastify/tests/fastify.spec.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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',
Expand All @@ -26,7 +42,7 @@ describe('fastify', () => {
body: JSON.stringify({
query: /* GraphQL */ `
{
pet_by_petId(petId: "pet200") {
petByPetId(petId: "pet200") {
name
}
}
Expand All @@ -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 () => {
Expand All @@ -47,7 +66,7 @@ describe('fastify', () => {
body: JSON.stringify({
query: /* GraphQL */ `
{
pet_by_petId(petId: "pet500") {
petByPetId(petId: "pet500") {
name
}
}
Expand All @@ -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' },
Expand Down
42 changes: 8 additions & 34 deletions packages/handlers/openapi/src/index.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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,
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand All @@ -286,6 +286,5 @@ function argsFromArgMap(argMap: ArgsMap, args: any) {
originalArgs[originalArgName] = val;
}
});

return originalArgs;
}