File tree Expand file tree Collapse file tree 8 files changed +416
-28
lines changed Expand file tree Collapse file tree 8 files changed +416
-28
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ ' @graphql-eslint/eslint-plugin ' : minor
3+ ---
4+
5+ Improve ` parseForESLint ` API and allow to pass context schema as inline string.
6+
7+ You can now use it this way:
8+
9+ ``` ts
10+ parseForESLint (code , { schemaSdl: " type Query { foo: String }" , filePath: ' test.graphql' });
11+ ```
Original file line number Diff line number Diff line change @@ -206,3 +206,355 @@ exports[`Parser > parseForESLint() should return ast and tokens 1`] = `
206206 type: Program,
207207}
208208`;
209+
210+ exports[ ` Parser > should allow to pass inline schema string as input 1 ` ] = `
211+ {
212+ body: [
213+ {
214+ definitions: [
215+ {
216+ description: undefined,
217+ directives: [ ] ,
218+ fields: [
219+ {
220+ arguments: [ ] ,
221+ description: undefined,
222+ directives: [ ] ,
223+ gqlType: {
224+ kind: NamedType,
225+ leadingComments: [ ] ,
226+ loc: {
227+ end: {
228+ column: 19,
229+ line: 3,
230+ },
231+ source:
232+ type Query {
233+ foo: String
234+ }
235+ ,
236+ start: {
237+ column: 13,
238+ line: 3,
239+ },
240+ },
241+ name: {
242+ kind: Name,
243+ leadingComments: [ ] ,
244+ loc: {
245+ end: {
246+ column: 19,
247+ line: 3,
248+ },
249+ source:
250+ type Query {
251+ foo: String
252+ }
253+ ,
254+ start: {
255+ column: 13,
256+ line: 3,
257+ },
258+ },
259+ range: [
260+ 33,
261+ 39,
262+ ] ,
263+ rawNode: [ Function] ,
264+ type: Name,
265+ typeInfo: [ Function] ,
266+ value: String,
267+ },
268+ range: [
269+ 33,
270+ 39,
271+ ] ,
272+ rawNode: [ Function] ,
273+ type: NamedType,
274+ typeInfo: [ Function] ,
275+ },
276+ kind: FieldDefinition,
277+ leadingComments: [ ] ,
278+ loc: {
279+ end: {
280+ column: 13,
281+ line: 3,
282+ },
283+ source:
284+ type Query {
285+ foo: String
286+ }
287+ ,
288+ start: {
289+ column: 8,
290+ line: 3,
291+ },
292+ },
293+ name: {
294+ kind: Name,
295+ leadingComments: [ ] ,
296+ loc: {
297+ end: {
298+ column: 11,
299+ line: 3,
300+ },
301+ source:
302+ type Query {
303+ foo: String
304+ }
305+ ,
306+ start: {
307+ column: 8,
308+ line: 3,
309+ },
310+ },
311+ range: [
312+ 28,
313+ 31,
314+ ] ,
315+ rawNode: [ Function] ,
316+ type: Name,
317+ typeInfo: [ Function] ,
318+ value: foo,
319+ },
320+ range: [
321+ 28,
322+ 39,
323+ ] ,
324+ rawNode: [ Function] ,
325+ type: FieldDefinition,
326+ typeInfo: [ Function] ,
327+ },
328+ ] ,
329+ interfaces: [ ] ,
330+ kind: ObjectTypeDefinition,
331+ leadingComments: [ ] ,
332+ loc: {
333+ end: {
334+ column: 46,
335+ line: 4,
336+ },
337+ source:
338+ type Query {
339+ foo: String
340+ }
341+ ,
342+ start: {
343+ column: 6,
344+ line: 2,
345+ },
346+ },
347+ name: {
348+ kind: Name,
349+ leadingComments: [ ] ,
350+ loc: {
351+ end: {
352+ column: 16,
353+ line: 2,
354+ },
355+ source:
356+ type Query {
357+ foo: String
358+ }
359+ ,
360+ start: {
361+ column: 11,
362+ line: 2,
363+ },
364+ },
365+ range: [
366+ 12,
367+ 17,
368+ ] ,
369+ rawNode: [ Function] ,
370+ type: Name,
371+ typeInfo: [ Function] ,
372+ value: Query,
373+ },
374+ range: [
375+ 7,
376+ 47,
377+ ] ,
378+ rawNode: [ Function] ,
379+ type: ObjectTypeDefinition,
380+ typeInfo: [ Function] ,
381+ },
382+ ] ,
383+ kind: Document,
384+ leadingComments: [ ] ,
385+ loc: {
386+ end: {
387+ column: 4,
388+ line: 5,
389+ },
390+ source:
391+ type Query {
392+ foo: String
393+ }
394+ ,
395+ start: {
396+ column: 0,
397+ line: 1,
398+ },
399+ },
400+ range: [
401+ 0,
402+ 52,
403+ ] ,
404+ rawNode: [ Function] ,
405+ type: Document,
406+ typeInfo: [ Function] ,
407+ },
408+ ] ,
409+ comments: [ ] ,
410+ loc: {
411+ end: {
412+ column: 4,
413+ line: 5,
414+ },
415+ source:
416+ type Query {
417+ foo: String
418+ }
419+ ,
420+ start: {
421+ column: 0,
422+ line: 1,
423+ },
424+ },
425+ range: [
426+ 0,
427+ 52,
428+ ] ,
429+ sourceType: script,
430+ tokens: [
431+ {
432+ loc: {
433+ end: {
434+ column: 10,
435+ line: 2,
436+ },
437+ start: {
438+ column: 6,
439+ line: 2,
440+ },
441+ },
442+ range: [
443+ 7,
444+ 11,
445+ ] ,
446+ type: Name,
447+ value: type,
448+ },
449+ {
450+ loc: {
451+ end: {
452+ column: 16,
453+ line: 2,
454+ },
455+ start: {
456+ column: 11,
457+ line: 2,
458+ },
459+ },
460+ range: [
461+ 12,
462+ 17,
463+ ] ,
464+ type: Name,
465+ value: Query,
466+ },
467+ {
468+ loc: {
469+ end: {
470+ column: 18,
471+ line: 2,
472+ },
473+ start: {
474+ column: 17,
475+ line: 2,
476+ },
477+ },
478+ range: [
479+ 18,
480+ 19,
481+ ] ,
482+ type: {,
483+ value: undefined,
484+ },
485+ {
486+ loc: {
487+ end: {
488+ column: 11,
489+ line: 3,
490+ },
491+ start: {
492+ column: 8,
493+ line: 3,
494+ },
495+ },
496+ range: [
497+ 28,
498+ 31,
499+ ] ,
500+ type: Name,
501+ value: foo,
502+ },
503+ {
504+ loc: {
505+ end: {
506+ column: 12,
507+ line: 3,
508+ },
509+ start: {
510+ column: 11,
511+ line: 3,
512+ },
513+ },
514+ range: [
515+ 31,
516+ 32,
517+ ] ,
518+ type: :,
519+ value: undefined,
520+ },
521+ {
522+ loc: {
523+ end: {
524+ column: 19,
525+ line: 3,
526+ },
527+ start: {
528+ column: 13,
529+ line: 3,
530+ },
531+ },
532+ range: [
533+ 33,
534+ 39,
535+ ] ,
536+ type: Name,
537+ value: String,
538+ },
539+ {
540+ loc: {
541+ end: {
542+ column: 7,
543+ line: 4,
544+ },
545+ start: {
546+ column: 6,
547+ line: 4,
548+ },
549+ },
550+ range: [
551+ 46,
552+ 47,
553+ ] ,
554+ type: },
555+ value: undefined,
556+ },
557+ ] ,
558+ type: Program,
559+ }
560+ `;
Original file line number Diff line number Diff line change 11import { parseForESLint } from '../src/parser.js' ;
22
33describe ( 'Parser' , ( ) => {
4+ it ( 'should allow to pass inline schema string as input' , ( ) => {
5+ const code = /* GraphQL */ `
6+ type Query {
7+ foo: String
8+ }
9+ ` ;
10+
11+ const result = parseForESLint ( code , { schemaSdl : code , filePath : 'test.graphql' } ) ;
12+ expect ( result . ast ) . toMatchSnapshot ( ) ;
13+ expect ( result . ast . tokens ) . toBeTruthy ( ) ;
14+ } ) ;
15+
416 it ( 'parseForESLint() should return ast and tokens' , ( ) => {
517 const code = /* GraphQL */ `
618 """
You can’t perform that action at this time.
0 commit comments