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

GraphQL query builder functions do not generate output fields for nested queries #5969

Closed
KXLAA opened this issue May 6, 2024 · 0 comments · Fixed by #5976
Closed

GraphQL query builder functions do not generate output fields for nested queries #5969

KXLAA opened this issue May 6, 2024 · 0 comments · Fixed by #5976

Comments

@KXLAA
Copy link
Contributor

KXLAA commented May 6, 2024

Faling test PR

You have a RX schema for a document in your collection with nested fields:

const mySchema = {
    version: 0,
    primaryKey: 'passportId',
    type: 'object',
    properties: {
        passportId: {
            type: 'string',
            maxLength: 100,
        },
        firstName: {
            type: 'string',
        },
        lastName: {
            type: 'string',
        },
        age: {
            type: 'integer',
            minimum: 0,
            maximum: 150,
        },
        updatedAt: {
            type: 'string',
        },
        address: {
            type: 'object',
            properties: {
                street: {
                    type: 'string',
                },
                city: {
                    type: 'string',
                },
                zip: {
                    type: 'string',
                },
            },
        },
    },
};

You want to generate GraphQL queries from this schema to support replication using the pullQueryBuilderFromRxSchema, pullStreamBuilderFromRxSchema & pushQueryBuilderFromRxSchema util functions.

Currently, the query builder functions only generate output fields for top-level keys. So given mySchema above we get the following pull query when we pass the schema to the pullQueryBuilderFromRxSchema:

query PullHuman($checkpoint: HumanInputCheckpoint, $limit: Int!) {
  pullHuman(checkpoint: $checkpoint, limit: $limit) {
    documents {
      passportId
      firstName
      lastName
      age
      updatedAt
      address 
      _deleted
    }
    checkpoint {
      passportId
      updatedAt
    }
  }
}

As you can see, the properties of address are not generated and this causes a GraphQL validation error :

GraphQLError: Field \"address\" of type \"HumanModel\" must have a selection of subfields.

ideally, the function should be able to generate output fields for nested objects as well:

query PullHuman($checkpoint: HumanInputCheckpoint, $limit: Int!) {
  pullHuman(checkpoint: $checkpoint, limit: $limit) {
    documents {
      passportId
      firstName
      lastName
      age
      updatedAt
      address {
        street
        city
        zip
      }
      _deleted
    }
    checkpoint {
      passportId
      updatedAt
    }
  }
}
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

Successfully merging a pull request may close this issue.

1 participant