Skip to content

parse comments beginning with ## as descriptions on schema definitions #427

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/language/__tests__/lexer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,19 @@ describe('Lexer', () => {
);
});

it('lexes description comments', () => {

expect(
lexOne('## test description')
).to.deep.equal({
kind: TokenKind.DESCRIPTION,
start: 0,
end: 19,
value: 'test description'
});

});

it('lexes punctuation', () => {

expect(
Expand Down
26 changes: 26 additions & 0 deletions src/language/__tests__/schema-kitchen-sink.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -10,65 +10,91 @@ schema {
mutation: MutationType
}

## description of 'Foo'
## with multiple lines
type Foo implements Bar {

## description of field 'one'
one: Type

two(argument: InputType!): Type
three(argument: InputType, other: String): Int
four(argument: String = "string"): String
five(argument: [String] = ["string", "string"]): String
six(argument: InputType = {key: "value"}): Type
}

## description of 'AnnotatedObject'
type AnnotatedObject @onObject(arg: "value") {
annotatedField(arg: Type = "default" @onArg): Type @onField
}

## description of 'Bar'
interface Bar {
one: Type
## description of field 'four'
four(argument: String = "string"): String
}

## description of 'AnnotatedInterface'
interface AnnotatedInterface @onInterface {
annotatedField(arg: Type @onArg): Type @onField
}

## description of 'Feed'
union Feed = Story | Article | Advert

## description of 'AnnotatedUnion'
union AnnotatedUnion @onUnion = A | B

## description of 'CustomScalar'
scalar CustomScalar

## description of 'AnnotatedScalar'
scalar AnnotatedScalar @onScalar

## description of 'Site'
enum Site {
DESKTOP

## description of enum value 'MOBILE'
MOBILE
}

## description of 'AnnotatedEnum'
enum AnnotatedEnum @onEnum {
## description of enum value 'ANNOTATED_VALUE'
ANNOTATED_VALUE @onEnumValue
## description of enum value 'OTHER_VALUE'
OTHER_VALUE
}

## description of 'InputType'
input InputType {
key: String!
## description of field 'answer'
answer: Int = 42
}

## description of 'AnnotatedInput'
input AnnotatedInput @onInputObjectType {
annotatedField: Type @onField
}

extend type Foo {
## description of field 'seven'
seven(argument: [String]): Type
}

extend type Foo @onType {}

## description of 'NoFields'
type NoFields {}

## description of '@skip'
directive @skip(if: Boolean!) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT

## description of '@include'
directive @include(if: Boolean!)
on FIELD
| FRAGMENT_SPREAD
Expand Down
Loading