graphql-tools icon indicating copy to clipboard operation
graphql-tools copied to clipboard

Bug: HoistField does not support List in path

Open ntziolis opened this issue 3 years ago • 2 comments

When hoisting a field and the path to the field contains a list the resulting schema ignores that there was a list in the path.

To Reproduce Given the following schema:

type Query {
   data: [Wrapper!]!
}

type Wrapper {
   value: String!
}

Using the following configuration for hoist field:

new HoistField('Query', ['data', 'value'], 'data');

The result is:

type Query {
   data: String!
}

Expected behavior The hoist field transform should instead generate the followings schema

type Query {
   data: [String!]!
}

Note:

  • This should also work when there are multiple levels of lists (while supporting a single level of list would be the most crucial to support)

Additional context

Use case:

  • We often find legacy APIs that wrap list result data in above described structures
  • We use the HoistField transform (and others) to remove unnecessary nesting to provide a clean GraphQL API to consume

ntziolis avatar Nov 21 '21 09:11 ntziolis

Added simple unit test that covers this case: https://github.com/ntziolis/graphql-tools/commit/31070713e3498379454ec62d463e9236a0ad090a

ntziolis avatar Nov 21 '21 12:11 ntziolis

Would you create a PR with this failing test?

ardatan avatar Jan 13 '22 04:01 ardatan