Skip to content

How to share field definitions between inputObjectType and objectType definitions? #772

Answered by shreyas44
carnesen asked this question in Q&A
Discussion options

You must be logged in to vote

Hey @carnesen! I don't think there's a built in way to achieve what you're talking about. However, you could try using the below workaround. I haven't tested it, so I'm not sure if it would work or not.

const messageDefinition = (t) => {
  t.string("content")
  t.string("author")
}

const MessageInput = inputObjectType({
  name: "MessageInput",
  defintion: messageDefinition,
})

const Message = objectType({
  name: "Message",
  defintion(t) {
    t.id("id")
    messageDefinition(t)
  }
})

Replies: 1 comment 6 replies

Comment options

You must be logged in to vote
6 replies
@carnesen
Comment options

@NEO97online
Comment options

@rozsival
Comment options

@RubenMoraVargas
Comment options

@Frosty21
Comment options

Answer selected by carnesen
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
7 participants