graphql-query-rewriter / core

Seamlessly turn breaking GraphQL changes into non-breaking changes
https://graphql-query-rewriter.github.io/core
MIT License
407 stars 15 forks source link

feat: ScalarFieldToObjectFieldRewriter #7

Closed chanind closed 4 years ago

chanind commented 4 years ago

This PR adds a new rewriter type called ScalarFieldToObjectFieldRewriter. This rewriter allows rewriting a field that's a scalar, like title: 'blah', to an object with a single nested scalar, like { title: { text: 'blah' } }.

For example, this would allow transitioning from a schema like:

type Article {
  title: String!
  ...
}

to

type ArticleTitle {
  text: String!
  localizedText: string
}

type Article {
  title: ArticleTitle!
 ...
}

The rewriter to do this would look like:

new ScalarFieldToObjectFieldRewriter({
    fieldName: 'title',
    objectFieldName: 'text'
})

Then, when an old query arrives requesting:

query {
  article(id: 123) {
    title
  }
}

this will be rewritten to

query {
  article(id: 123) {
    title {
      text
    }
  }
}
chanind commented 4 years ago

:tada: This PR is included in version 1.1.0 :tada:

The release is available on:

Your semantic-release bot :package::rocket: