'Handle types with identical properties in GraphQL
I've joined a codebase that used GraphQL and is in dire need of DRYing up. Example code would look like this:
/plugins/abc/schemas/user.js
const { gql } = require('apollo-server-express')
module.export.defTypes = gql`
type User {
name: String
id: String
location: String
}
`
/plugins/def/schemas/user.js
const { gql } = require('apollo-server-express')
module.export.defTypes = gql`
type User {
name: String
id: String
location: String
}
`
I don't know GraphQL terribly well, but given that this was just exporting string content, I assumed I could do this:
/plugins/def/schemas/user.js
const { gql } = require('apollo-server-express');
const { user } = require('../shared/schemas');
module.export.defTypes = gql`
type User {
${user}
}
But graphQL throws up an error:
(node:78551) UnhandledPromiseRejectionWarning: MissingSchemaError: Schema hasn't been registered for model "<name of unrelated model>".
Is there a correct, GraphQL-y way to do this?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
