You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Strip Common Indentation from BlockString Descriptions
Multi-line descriptions need to have their common indentation level
(which results from indentation of that part of the schema, rather than
being intentional for the description text) removed to ensure the
descriptions use the correct value, are formatted correctly etc
This is to meet the condition documented in the GraphQL spec:
https://graphql.github.io/graphql-spec/June2018/#sec-String-Value
> Since block strings represent freeform text often used in indented
> positions, the string value semantics of a block string excludes
> uniform indentation and blank initial and trailing lines via
> BlockStringValue().
name: "Parses type with multi-line description and ignores comments",
98
+
name: "Parses type with empty multi-line 'BlockString' description",
99
+
sdl: `
100
+
"""
101
+
"""
102
+
type Type {
103
+
field: String
104
+
}`,
105
+
useStringDescriptions: true,
106
+
validateSchema: func(s*schema.Schema) error {
107
+
consttypeName="Type"
108
+
typ, ok:=s.Types[typeName].(*schema.Object)
109
+
if!ok {
110
+
returnfmt.Errorf("type %q not found", typeName)
111
+
}
112
+
ifwant, have:="", typ.Description(); want!=have {
113
+
returnfmt.Errorf("invalid description: want %q, have %q", want, have)
114
+
}
115
+
returnnil
116
+
},
117
+
},
118
+
{
119
+
name: "Parses type with multi-line 'BlockString' description",
120
+
sdl: `
121
+
"""
122
+
First line of the description.
123
+
124
+
Second line of the description.
125
+
126
+
query {
127
+
code {
128
+
example
129
+
}
130
+
}
131
+
132
+
Notes:
133
+
134
+
* First note
135
+
* Second note
136
+
"""
137
+
type Type {
138
+
field: String
139
+
}`,
140
+
useStringDescriptions: true,
141
+
validateSchema: func(s*schema.Schema) error {
142
+
consttypeName="Type"
143
+
typ, ok:=s.Types[typeName].(*schema.Object)
144
+
if!ok {
145
+
returnfmt.Errorf("type %q not found", typeName)
146
+
}
147
+
want:="First line of the description.\n\nSecond line of the description.\n\n\tquery {\n\t\tcode {\n\t\t\texample\n\t\t}\n\t}\n\nNotes:\n\n * First note\n * Second note"
148
+
ifhave:=typ.Description(); want!=have {
149
+
returnfmt.Errorf("invalid description: want %q, have %q", want, have)
150
+
}
151
+
returnnil
152
+
},
153
+
},
154
+
{
155
+
name: "Parses type with un-indented multi-line 'BlockString' description",
156
+
sdl: `
157
+
"""
158
+
First line of the description.
159
+
160
+
Second line of the description.
161
+
"""
162
+
type Type {
163
+
field: String
164
+
}`,
165
+
useStringDescriptions: true,
166
+
validateSchema: func(s*schema.Schema) error {
167
+
consttypeName="Type"
168
+
typ, ok:=s.Types[typeName].(*schema.Object)
169
+
if!ok {
170
+
returnfmt.Errorf("type %q not found", typeName)
171
+
}
172
+
want:="First line of the description.\n\nSecond line of the description."
173
+
ifhave:=typ.Description(); want!=have {
174
+
returnfmt.Errorf("invalid description: want %q, have %q", want, have)
175
+
}
176
+
returnnil
177
+
},
178
+
},
179
+
{
180
+
name: "Parses type with space-indented multi-line 'BlockString' description",
181
+
sdl: `
182
+
"""
183
+
First line of the description.
184
+
185
+
Second line of the description.
186
+
187
+
query {
188
+
code {
189
+
example
190
+
}
191
+
}
192
+
"""
193
+
type Type {
194
+
field: String
195
+
}`,
196
+
useStringDescriptions: true,
197
+
validateSchema: func(s*schema.Schema) error {
198
+
consttypeName="Type"
199
+
typ, ok:=s.Types[typeName].(*schema.Object)
200
+
if!ok {
201
+
returnfmt.Errorf("type %q not found", typeName)
202
+
}
203
+
want:="First line of the description.\n\nSecond line of the description.\n\n query {\n code {\n example\n }\n }"
204
+
ifhave:=typ.Description(); want!=have {
205
+
returnfmt.Errorf("invalid description: want %q, have %q", want, have)
206
+
}
207
+
returnnil
208
+
},
209
+
},
210
+
{
211
+
name: "Parses type with multi-line 'BlockString' description and ignores comments",
0 commit comments