TL;DR: A mechanism for allowing fields to be shared between an object type and an input object type just does not exist. Fragments can only be used client-side when composing queries.
From the specification:
Fragments allow for the reuse of common repeated selections of fields, reducing duplicated text in the document.
The intent behind fragments is that you may have any number of saved queries that query the same type -- you don't want to have to update 20 different queries if the schema changes or you decide you don't need a certain field anymore.
A similar mechanism for allowing fields to be shared between a Type and an Input Type server-side just does not exist. This is likely largely by design because even though a Type field and an Input Type field both have some kind of type
, they may have other properties. For example, Input Type fields can have a default value, while that property does not exist for a Type field. Similarly, Type fields have resolvers and arguments, which Input Type fields do not.
If you really want to keep things DRY, there may be workarounds available, depending on what kind of GraphQL server you're running. If it's a GraphQL.js server that uses a schema created from one or more SDL strings, for example, you can just use template literals:
const sharedClientFields = `
short_name: String
full_name: String
address: String
email: String
location: String
`
const schema = `
type Client {
_id: String
${sharedClientFields}
}
type ClientInput {
${sharedClientFields}
}
`