MCPcopy
hub / github.com/ardatan/graphql-tools / parseGraphQLSDL

Function parseGraphQLSDL

packages/utils/src/parse-graphql-sdl.ts:15–50  ·  view source on GitHub ↗
(
  location: string | undefined,
  rawSDL: string,
  options: GraphQLParseOptions = {},
)

Source from the content-addressed store, hash-verified

13import { GraphQLParseOptions } from './Interfaces.js';
14
15export 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
52export function transformCommentsToDescriptions(
53 sourceSdl: string,

Callers 12

extractDependenciesFunction · 0.90
handleFileContentMethod · 0.90
parseFunction · 0.90
handleResponseMethod · 0.90
handleSDLMethod · 0.90
loadMethod · 0.90
loadSyncMethod · 0.90
resolveSourceFunction · 0.90
collectDocumentStringFunction · 0.90
parseRawSDLFunction · 0.90

Calls 3

printFunction · 0.85
parseFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…