(
location: string | undefined,
rawSDL: string,
options: GraphQLParseOptions = {},
)
| 13 | import { GraphQLParseOptions } from './Interfaces.js'; |
| 14 | |
| 15 | export function parseGraphQLSDL( |
| 16 | location: string | undefined, |
| 17 | rawSDL: string, |
| 18 | options: GraphQLParseOptions = {}, |
| 19 | ) { |
| 20 | let document: DocumentNode; |
| 21 | |
| 22 | try { |
| 23 | if (options.commentDescriptions && rawSDL.includes('#')) { |
| 24 | document = transformCommentsToDescriptions(rawSDL, options); |
| 25 | |
| 26 | // If noLocation=true, we need to make sure to print and parse it again, to remove locations, |
| 27 | // since `transformCommentsToDescriptions` must have locations set in order to transform the comments |
| 28 | // into descriptions. |
| 29 | if (options.noLocation) { |
| 30 | document = parse(print(document), options); |
| 31 | } |
| 32 | } else { |
| 33 | document = parse(new GraphQLSource(rawSDL, location), options); |
| 34 | } |
| 35 | } catch (e: any) { |
| 36 | if (e.message.includes('EOF') && rawSDL.replace(/(\#[^*]*)/g, '').trim() === '') { |
| 37 | document = { |
| 38 | kind: Kind.DOCUMENT, |
| 39 | definitions: [], |
| 40 | }; |
| 41 | } else { |
| 42 | throw e; |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | return { |
| 47 | location, |
| 48 | document, |
| 49 | }; |
| 50 | } |
| 51 | |
| 52 | export function transformCommentsToDescriptions( |
| 53 | sourceSdl: string, |
no test coverage detected
searching dependent graphs…