Skip to content

Commit

Permalink
fix: unwrap non-null types (#340)
Browse files Browse the repository at this point in the history
On SX API we migrated to use non nullable lists in schema, for example
[Space!]! but this means we need to unwrap those to get actual type.
  • Loading branch information
Sekhmet authored Feb 13, 2025
1 parent f3e4417 commit 93dd08c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@snapshot-labs/checkpoint",
"version": "0.1.0-beta.48",
"version": "0.1.0-beta.49",
"license": "MIT",
"bin": {
"checkpoint": "dist/src/bin/index.js"
Expand Down
8 changes: 6 additions & 2 deletions src/graphql/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,12 @@ export class GqlEntityController {
entities[obj.name] = this.getTypeFields(obj).reduce((resolvers, field) => {
const nonNullType = getNonNullType(field.type);

if (isListType(nonNullType) && nonNullType.ofType instanceof GraphQLObjectType) {
resolvers[field.name] = getNestedResolver(multiEntityQueryName(nonNullType.ofType));
if (isListType(nonNullType)) {
const itemType = getNonNullType(nonNullType.ofType);

if (itemType instanceof GraphQLObjectType) {
resolvers[field.name] = getNestedResolver(multiEntityQueryName(itemType));
}
}

if (nonNullType instanceof GraphQLObjectType) {
Expand Down
11 changes: 7 additions & 4 deletions src/graphql/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,9 @@ export async function queryMulti(
): Promise<Result[]> {
const { log, knex } = context;

if (!isListType(info.returnType)) throw new Error('unexpected return type');
const returnType = info.returnType.ofType as GraphQLObjectType;
const nonNullType = getNonNullType(info.returnType);
if (!isListType(nonNullType)) throw new Error('unexpected return type');
const returnType = getNonNullType(nonNullType.ofType) as GraphQLObjectType;
const jsonFields = getJsonFields(returnType);

const tableName = getTableName(returnType.name.toLowerCase());
Expand Down Expand Up @@ -299,8 +300,10 @@ export const getNestedResolver =
indexer: parent._args?.indexer
};

const returnType = getNonNullType(info.returnType) as GraphQLList<GraphQLObjectType>;
const jsonFields = getJsonFields(returnType.ofType);
const returnType = getNonNullType(info.returnType) as
| GraphQLList<GraphQLObjectType>
| GraphQLList<GraphQLNonNull<GraphQLObjectType>>;
const jsonFields = getJsonFields(getNonNullType(returnType.ofType) as GraphQLObjectType);

const parentType = getNonNullType(info.parentType) as GraphQLObjectType;
const field = parentType.getFields()[info.fieldName];
Expand Down

0 comments on commit 93dd08c

Please sign in to comment.