Extending types For Data Modelling in GraphQL

Extending types For Data Modelling in GraphQL

What are Type Extensions

type Person {
id: String
name: String
age: Int
}

extend type Person {
email: String
}
type Person {
id: String
name: String
age: Int
}

extend type Person {
email: String
@materializer (query: "getPersonEmail", arguments: [{name: "personId", field: "id"}]
}

type Query {
getPerson(id: ID!): Person
@dbquery(
type: "mysql"
table: "person"
configuration: "mysql_config"
)
getPersonEmail(personId: ID!): String
@rest (endpoint: "https://some.crm.com/api/person/$personId/email")
}

Extending types versus inheritance

interface Employee {
id: ID
name: String
email: String
}

type FullTimeEmployee implements Employee {
id: ID
name: String
email: String
monthlyWage: Float
}

type SeasonalEmployee implements Employee {
id: ID
name: String
email: String
hourlyWage: Float
season: String
}

Conclusion

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Roy Derks (@gethackteam)

Roy Derks (@gethackteam)

1K Followers

Roy is an entrepreneur, speaker and author from The Netherlands. Most recently he wrote the books Fullstack GraphQL and React Projects.