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

BuildFields type is incorrect? #91

Closed
daa opened this issue Apr 19, 2022 · 3 comments
Closed

BuildFields type is incorrect? #91

daa opened this issue Apr 19, 2022 · 3 comments

Comments

@daa
Copy link
Contributor

daa commented Apr 19, 2022

BuildFields type is defined as a function returning IntrospectionObjectType[]:

type BuildFields = (
  type: IntrospectionObjectType,
  aorFetchType?: FetchType
) => IntrospectionObjectType[];

But buildFields function actually constructs FieldNode[] list accumulating gqlTypes.field() results which are FieldNode objects:

const buildFields: BuildFields = (type) =>
  type.fields.reduce((acc, field) => {
    const type = getFinalType(field.type);

    if (type.kind !== TypeKind.OBJECT && type.kind !== TypeKind.INTERFACE) {
      return [...acc, gqlTypes.field(gqlTypes.name(field.name))];
    }

    return acc;
  }, [] as IntrospectionObjectType[]);

May be I don't understand something but actual value returned from buildFields() function look like FieldNode[] and not like IntrospectionObjectType[] and they are used where FieldNode[] is expected and not IntrospectionNodeType[]:

const fields = buildFields(resource.type, aorFetchType);
if (
aorFetchType === GET_LIST ||
aorFetchType === GET_MANY ||
aorFetchType === GET_MANY_REFERENCE
) {
return gqlTypes.document([
gqlTypes.operationDefinition(
'query',
gqlTypes.selectionSet([
gqlTypes.field(
gqlTypes.name(queryType.name),
gqlTypes.name('items'),
args,
null,
gqlTypes.selectionSet(fields)
.

@cpv123
Copy link

cpv123 commented Apr 24, 2022

@daa you are correct, good spot. I've raised this PR to fix it: #93

@daa
Copy link
Contributor Author

daa commented Apr 29, 2022

Thank you very much!

@cpv123
Copy link

cpv123 commented May 9, 2022

This was fixed in #93

@daa daa closed this as completed May 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants