Skip to content

Commit

Permalink
Fix bug with incorrect method names
Browse files Browse the repository at this point in the history
  • Loading branch information
captbaritone committed May 4, 2024
1 parent 808a452 commit ae2a667
Show file tree
Hide file tree
Showing 9 changed files with 120 additions and 7 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Expand Up @@ -10,8 +10,9 @@ Changes in this section are not yet released. If you need access to these change
- Fields can now be defined using static methods, similar to how fields can be defined using functions
- Adds `importModuleSpecifierEnding` configuration option to enable users generating ES modules to add the `.js` file extension to import paths in the generated TypeScript schema file
- **Bug Fixes**
- Revert accidental breakage of the experimental TypeScript plugin
- Fix a bug where we generated incorrect import paths on Windows
- Reverted accidental breakage of the experimental TypeScript plugin
- Fixed a bug where we generated incorrect import paths on Windows
- Fixed a bug where incorrect resolver arguments were passed to method resolvers which provided custom names

## 0.0.25

Expand Down
2 changes: 1 addition & 1 deletion src/codegen.ts
Expand Up @@ -290,7 +290,7 @@ class Codegen {
valueExpression = F.createCallExpression(
prop,
undefined,
RESOLVER_ARGS.map((name) => {
RESOLVER_ARGS.slice(1).map((name) => {
return F.createIdentifier(name);
}),
);
Expand Down
Expand Up @@ -38,7 +38,7 @@ export function getSchema(): GraphQLSchema {
name: "salutaion",
type: GraphQLString,
resolve(source, args, context, info) {
return source.someMethodField(source, args, context, info);
return source.someMethodField(args, context, info);
}
}
};
Expand Down
Expand Up @@ -33,7 +33,7 @@ export function getSchema(): GraphQLSchema {
}
},
resolve(source, args, context, info) {
return source.hello(source, args, context, info);
return source.hello(args, context, info);
}
}
};
Expand Down
Expand Up @@ -50,7 +50,7 @@ export function getSchema(): GraphQLSchema {
name: "salutaion",
type: GraphQLString,
resolve(source, args, context, info) {
return source.someMethodField(source, args, context, info);
return source.someMethodField(args, context, info);
}
}
};
Expand Down
Expand Up @@ -31,7 +31,7 @@ export function getSchema(): GraphQLSchema {
name: "name",
type: GraphQLString,
resolve(source, args, context, info) {
return source.graphQLName(source, args, context, info);
return source.graphQLName(args, context, info);
}
}
};
Expand Down
28 changes: 28 additions & 0 deletions src/tests/integrationFixtures/aliasedMethod/index.ts
@@ -0,0 +1,28 @@
type GraphqlContext = {};

/** @gqlType */
type Query = unknown;

/** @gqlField */
export function someType(_: Query): SomeType {
return new SomeType();
}

/** @gqlType */
class SomeType {
/** @gqlField someName */
async someOtherName(
args: { greeting: string },
ctx: GraphqlContext,
): Promise<string> {
return `${args.greeting} World!`;
}
}

export const query = /* GraphQL */ `
query {
someType {
someName(greeting: "Hello")
}
}
`;
42 changes: 42 additions & 0 deletions src/tests/integrationFixtures/aliasedMethod/index.ts.expected
@@ -0,0 +1,42 @@
-----------------
INPUT
-----------------
type GraphqlContext = {};

/** @gqlType */
type Query = unknown;

/** @gqlField */
export function someType(_: Query): SomeType {
return new SomeType();
}

/** @gqlType */
class SomeType {
/** @gqlField someName */
async someOtherName(
args: { greeting: string },
ctx: GraphqlContext,
): Promise<string> {
return `${args.greeting} World!`;
}
}

export const query = /* GraphQL */ `
query {
someType {
someName(greeting: "Hello")
}
}
`;

-----------------
OUTPUT
-----------------
{
"data": {
"someType": {
"someName": "Hello World!"
}
}
}
42 changes: 42 additions & 0 deletions src/tests/integrationFixtures/aliasedMethod/schema.ts
@@ -0,0 +1,42 @@
import { someType as querySomeTypeResolver } from "./index";
import { GraphQLSchema, GraphQLObjectType, GraphQLString, GraphQLNonNull } from "graphql";
export function getSchema(): GraphQLSchema {
const SomeTypeType: GraphQLObjectType = new GraphQLObjectType({
name: "SomeType",
fields() {
return {
someName: {
name: "someName",
type: GraphQLString,
args: {
greeting: {
name: "greeting",
type: new GraphQLNonNull(GraphQLString)
}
},
resolve(source, args, context, info) {
return source.someOtherName(args, context, info);
}
}
};
}
});
const QueryType: GraphQLObjectType = new GraphQLObjectType({
name: "Query",
fields() {
return {
someType: {
name: "someType",
type: SomeTypeType,
resolve(source) {
return querySomeTypeResolver(source);
}
}
};
}
});
return new GraphQLSchema({
query: QueryType,
types: [QueryType, SomeTypeType]
});
}

0 comments on commit ae2a667

Please sign in to comment.