This repository has been archived by the owner on Sep 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 70
Add schema comments to type definitions. #35
Comments
Not quite figured this, looking like the details come though on the original import { GraphQLSchema, GraphQLObjectType, GraphQLString, GraphQLID, GraphQLInterfaceType, GraphQLNonNull } from "graphql";
import {GraphQLCompilerContext, IRTransforms, transformASTSchema} from 'relay-compiler'
import * as parseGraphQLText from 'relay-test-utils/lib/parseGraphQLText'
import * as TypeScriptGenerator from '../src/TypeScriptGenerator'
const DogNameDescription = "Ideally short and sweet"
export const NodeInterface = new GraphQLInterfaceType({
name: "Node",
description: "An object with a Globally Unique ID",
fields: () => ({
id: {
type: new GraphQLNonNull(GraphQLID),
description: "The ID of the object.",
},
}),
})
const DogType = new GraphQLObjectType({
name: 'Dog',
fields: {
id: { type: new GraphQLNonNull(GraphQLID) },
name: { type: GraphQLString, description: DogNameDescription }
},
interfaces: [NodeInterface],
})
const schema = new GraphQLSchema({
query: new GraphQLObjectType({
name: 'Query',
fields: {
doggo: {
type: DogType,
args: {
id: { type: new GraphQLNonNull(GraphQLID) }
}
}
}
})
})
test("handles adding the comment on a field", () => {
const text = `
fragment HandlesCommentsFragment on Node {
id
... on Dog {
name
}
}
`
const {definitions} = parseGraphQLText(schema, text);
const tsInterface = new GraphQLCompilerContext(schema, schema)
.addAll(definitions)
.applyTransforms(TypeScriptGenerator.transforms)
.documents()
.map(doc =>
TypeScriptGenerator.generate(doc, {
customScalars: {},
enumsHasteModule: null,
existingFragmentNames: new Set(['PhotoFragment']),
inputFieldWhiteList: [],
relayRuntimeModule: 'relay-runtime',
useHaste: true,
}),
)
.join('\n\n');
expect(tsInterface).toContain(DogNameDescription)
}) |
Without having looked too much into it. I think some changes to the relay code might be needed to make this work. The way I see it, the IR representation should contain the comments. See the TS type definitions here (copy/pasted and adapted from flow code from the relay code): https://github.com/relay-tools/relay-compiler-language-typescript/blob/master/types/graphql-compiler/core/GraphQLIR.d.ts. But perhaps some dialog with the Relay team is in order wrt. solving this. |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
As per @orta’s comment, we should add schema comments as documentation to the type definitions.
The text was updated successfully, but these errors were encountered: