Skip to content

Conversation

@iamakulov
Copy link
Contributor

This is a follow-up for #10. Sorry I figured this late.

I’ve been trying graphql-compose-json in my project and realized that calculating types based on the first item of an array is not the best choice. If you have an array of objects returned from an API, some of those objects might omit some optional fields – and, as a result, those fields won’t get included into the generated schema.

For example, for the following JSON:

{
  name: 'Luke Skywalker',
  limbs: [
    { kind: 'arm', position: 'left', length: 76 },
    { kind: 'arm', position: 'right', length: 76, ring: true }
  ],
}

the type of the limbs property will be calculated roughly as follows:

type Person_Limbs {
  kind: String
  position: String
  length: String
} 

– and won’t include the ring field.

This PR improves that by calling getFieldConfig over Object.assign({}, ...array) instead of array[0]. Technically, this is a breaking change, but given that 4.1.0 was released just yesterday, I doubt somebody got relying on the previous behavior.

@nodkz nodkz merged commit 6d6d8f8 into graphql-compose:master Aug 21, 2019
@nodkz
Copy link
Member

nodkz commented Aug 21, 2019

Thanks a lot!
Sorry for the late response.

@nodkz
Copy link
Member

nodkz commented Aug 21, 2019

🎉 This PR is included in version 4.1.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

@nodkz nodkz added the released label Aug 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants