Skip to content

Commit

Permalink
Remove unneeded __typenames from examples
Browse files Browse the repository at this point in the history
  • Loading branch information
captbaritone committed Jul 9, 2024
1 parent 1f1232d commit f526198
Show file tree
Hide file tree
Showing 12 changed files with 114 additions and 12 deletions.
1 change: 0 additions & 1 deletion examples/apollo-server/models/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import Group from "./Group";

/** @gqlType User */
export default class UserResolver implements IPerson {
__typename = "User" as const;
/** @gqlField */
name(): string {
return "Alice";
Expand Down
20 changes: 19 additions & 1 deletion examples/apollo-server/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* Executable schema generated by Grats (https://grats.capt.dev)
* Do not manually edit. Regenerate by running `npx grats`.
*/
import UserClass from "./models/User";
import { allUsers as queryAllUsersResolver } from "./models/User";
import { me as queryMeResolver } from "./Query";
import { person as queryPersonResolver } from "./Query";
Expand Down Expand Up @@ -35,7 +36,8 @@ export function getSchema(): GraphQLSchema {
type: new GraphQLNonNull(GraphQLString)
}
};
}
},
resolveType
});
const UserType: GraphQLObjectType = new GraphQLObjectType({
name: "User",
Expand Down Expand Up @@ -88,3 +90,19 @@ export function getSchema(): GraphQLSchema {
types: [IPersonType, GroupType, QueryType, UserType]
});
}
const typeNameMap = new Map();
typeNameMap.set(UserClass, "User");
function resolveType(obj: any): string {
if (typeof obj.__typename === "string") {
return obj.__typename;
}
let prototype = Object.getPrototypeOf(obj);
while (prototype) {
const name = typeNameMap.get(prototype.constructor);
if (name != null) {
return name;
}
prototype = Object.getPrototypeOf(prototype);
}
throw new Error("Cannot find type name.");
}
1 change: 0 additions & 1 deletion examples/express-graphql-http/models/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import Group from "./Group";

/** @gqlType User */
export default class UserResolver implements IPerson {
__typename = "User" as const;
/** @gqlField */
name(): string {
return "Alice";
Expand Down
20 changes: 19 additions & 1 deletion examples/express-graphql-http/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* Executable schema generated by Grats (https://grats.capt.dev)
* Do not manually edit. Regenerate by running `npx grats`.
*/
import UserClass from "./models/User";
import { allUsers as queryAllUsersResolver } from "./models/User";
import { me as queryMeResolver } from "./Query";
import { person as queryPersonResolver } from "./Query";
Expand Down Expand Up @@ -35,7 +36,8 @@ export function getSchema(): GraphQLSchema {
type: new GraphQLNonNull(GraphQLString)
}
};
}
},
resolveType
});
const UserType: GraphQLObjectType = new GraphQLObjectType({
name: "User",
Expand Down Expand Up @@ -88,3 +90,19 @@ export function getSchema(): GraphQLSchema {
types: [IPersonType, GroupType, QueryType, UserType]
});
}
const typeNameMap = new Map();
typeNameMap.set(UserClass, "User");
function resolveType(obj: any): string {
if (typeof obj.__typename === "string") {
return obj.__typename;
}
let prototype = Object.getPrototypeOf(obj);
while (prototype) {
const name = typeNameMap.get(prototype.constructor);
if (name != null) {
return name;
}
prototype = Object.getPrototypeOf(prototype);
}
throw new Error("Cannot find type name.");
}
1 change: 0 additions & 1 deletion examples/express-graphql/models/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import Group from "./Group";

/** @gqlType User */
export default class UserResolver implements IPerson {
__typename = "User" as const;
/** @gqlField */
name(): string {
return "Alice";
Expand Down
20 changes: 19 additions & 1 deletion examples/express-graphql/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* Executable schema generated by Grats (https://grats.capt.dev)
* Do not manually edit. Regenerate by running `npx grats`.
*/
import UserClass from "./models/User";
import { allUsers as queryAllUsersResolver } from "./models/User";
import { me as queryMeResolver } from "./Query";
import { person as queryPersonResolver } from "./Query";
Expand Down Expand Up @@ -35,7 +36,8 @@ export function getSchema(): GraphQLSchema {
type: new GraphQLNonNull(GraphQLString)
}
};
}
},
resolveType
});
const UserType: GraphQLObjectType = new GraphQLObjectType({
name: "User",
Expand Down Expand Up @@ -88,3 +90,19 @@ export function getSchema(): GraphQLSchema {
types: [IPersonType, GroupType, QueryType, UserType]
});
}
const typeNameMap = new Map();
typeNameMap.set(UserClass, "User");
function resolveType(obj: any): string {
if (typeof obj.__typename === "string") {
return obj.__typename;
}
let prototype = Object.getPrototypeOf(obj);
while (prototype) {
const name = typeNameMap.get(prototype.constructor);
if (name != null) {
return name;
}
prototype = Object.getPrototypeOf(prototype);
}
throw new Error("Cannot find type name.");
}
1 change: 0 additions & 1 deletion examples/next-js/app/api/graphql/models/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import Group from "./Group";

/** @gqlType User */
export default class UserResolver implements IPerson {
__typename = "User" as const;
/** @gqlField */
name(): string {
return "Alice";
Expand Down
20 changes: 19 additions & 1 deletion examples/next-js/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* Executable schema generated by Grats (https://grats.capt.dev)
* Do not manually edit. Regenerate by running `npx grats`.
*/
import UserClass from "./app/api/graphql/models/User";
import { allUsers as queryAllUsersResolver } from "./app/api/graphql/models/User";
import { me as queryMeResolver } from "./app/api/graphql/Query";
import { person as queryPersonResolver } from "./app/api/graphql/Query";
Expand Down Expand Up @@ -35,7 +36,8 @@ export function getSchema(): GraphQLSchema {
type: new GraphQLNonNull(GraphQLString)
}
};
}
},
resolveType
});
const UserType: GraphQLObjectType = new GraphQLObjectType({
name: "User",
Expand Down Expand Up @@ -88,3 +90,19 @@ export function getSchema(): GraphQLSchema {
types: [IPersonType, GroupType, QueryType, UserType]
});
}
const typeNameMap = new Map();
typeNameMap.set(UserClass, "User");
function resolveType(obj: any): string {
if (typeof obj.__typename === "string") {
return obj.__typename;
}
let prototype = Object.getPrototypeOf(obj);
while (prototype) {
const name = typeNameMap.get(prototype.constructor);
if (name != null) {
return name;
}
prototype = Object.getPrototypeOf(prototype);
}
throw new Error("Cannot find type name.");
}
1 change: 0 additions & 1 deletion examples/strict-semantic-nullability/models/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import Group from "./Group";

/** @gqlType User */
export default class UserResolver implements IPerson {
__typename = "User" as const;
/** @gqlField */
name(): string {
return "Alice";
Expand Down
20 changes: 19 additions & 1 deletion examples/strict-semantic-nullability/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* Executable schema generated by Grats (https://grats.capt.dev)
* Do not manually edit. Regenerate by running `npx grats`.
*/
import UserClass from "./models/User";
import { allUsers as queryAllUsersResolver } from "./models/User";
import { me as queryMeResolver } from "./Query";
import { person as queryPersonResolver } from "./Query";
Expand Down Expand Up @@ -53,7 +54,8 @@ export function getSchema(): GraphQLSchema {
type: GraphQLString
}
};
}
},
resolveType
});
const UserType: GraphQLObjectType = new GraphQLObjectType({
name: "User",
Expand Down Expand Up @@ -156,3 +158,19 @@ export function getSchema(): GraphQLSchema {
types: [IPersonType, GroupType, QueryType, SubscriptionType, UserType]
});
}
const typeNameMap = new Map();
typeNameMap.set(UserClass, "User");
function resolveType(obj: any): string {
if (typeof obj.__typename === "string") {
return obj.__typename;
}
let prototype = Object.getPrototypeOf(obj);
while (prototype) {
const name = typeNameMap.get(prototype.constructor);
if (name != null) {
return name;
}
prototype = Object.getPrototypeOf(prototype);
}
throw new Error("Cannot find type name.");
}
1 change: 0 additions & 1 deletion examples/yoga/models/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import Group from "./Group";

/** @gqlType User */
export default class UserResolver implements IPerson {
__typename = "User" as const;
/** @gqlField */
name(): string {
return "Alice";
Expand Down
20 changes: 19 additions & 1 deletion examples/yoga/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* Executable schema generated by Grats (https://grats.capt.dev)
* Do not manually edit. Regenerate by running `npx grats`.
*/
import UserClass from "./models/User";
import { allUsers as queryAllUsersResolver } from "./models/User";
import { me as queryMeResolver } from "./Query";
import { person as queryPersonResolver } from "./Query";
Expand Down Expand Up @@ -36,7 +37,8 @@ export function getSchema(): GraphQLSchema {
type: new GraphQLNonNull(GraphQLString)
}
};
}
},
resolveType
});
const UserType: GraphQLObjectType = new GraphQLObjectType({
name: "User",
Expand Down Expand Up @@ -113,3 +115,19 @@ export function getSchema(): GraphQLSchema {
types: [IPersonType, GroupType, QueryType, SubscriptionType, UserType]
});
}
const typeNameMap = new Map();
typeNameMap.set(UserClass, "User");
function resolveType(obj: any): string {
if (typeof obj.__typename === "string") {
return obj.__typename;
}
let prototype = Object.getPrototypeOf(obj);
while (prototype) {
const name = typeNameMap.get(prototype.constructor);
if (name != null) {
return name;
}
prototype = Object.getPrototypeOf(prototype);
}
throw new Error("Cannot find type name.");
}

0 comments on commit f526198

Please sign in to comment.