Skip to content

Conversation

chanind
Copy link
Collaborator

@chanind chanind commented Oct 5, 2019

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 chanind changed the title Scalar field to object rewriter feat: ScalarFieldToObjectFieldRewriter Oct 6, 2019
@chanind chanind merged commit aee2dac into master Oct 6, 2019
@chanind chanind deleted the scalar-field-to-object-rewriter branch October 6, 2019 18:13
@chanind
Copy link
Collaborator Author

chanind commented Oct 6, 2019

🎉 This PR is included in version 1.1.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

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.

1 participant