Initialisation
Added the packages and files for the backend server
This commit is contained in:
40
node_modules/@graphql-tools/utils/esm/parse-graphql-json.js
generated
vendored
Normal file
40
node_modules/@graphql-tools/utils/esm/parse-graphql-json.js
generated
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
import { buildClientSchema } from 'graphql';
|
||||
function stripBOM(content) {
|
||||
content = content.toString();
|
||||
// Remove byte order marker. This catches EF BB BF (the UTF-8 BOM)
|
||||
// because the buffer-to-string conversion in `fs.readFileSync()`
|
||||
// translates it to FEFF, the UTF-16 BOM.
|
||||
if (content.charCodeAt(0) === 0xfeff) {
|
||||
content = content.slice(1);
|
||||
}
|
||||
return content;
|
||||
}
|
||||
function parseBOM(content) {
|
||||
return JSON.parse(stripBOM(content));
|
||||
}
|
||||
export function parseGraphQLJSON(location, jsonContent, options) {
|
||||
let parsedJson = parseBOM(jsonContent);
|
||||
if (parsedJson.data) {
|
||||
parsedJson = parsedJson.data;
|
||||
}
|
||||
if (parsedJson.kind === 'Document') {
|
||||
return {
|
||||
location,
|
||||
document: parsedJson,
|
||||
};
|
||||
}
|
||||
else if (parsedJson.__schema) {
|
||||
const schema = buildClientSchema(parsedJson, options);
|
||||
return {
|
||||
location,
|
||||
schema,
|
||||
};
|
||||
}
|
||||
else if (typeof parsedJson === 'string') {
|
||||
return {
|
||||
location,
|
||||
rawSDL: parsedJson,
|
||||
};
|
||||
}
|
||||
throw new Error(`Not valid JSON content`);
|
||||
}
|
||||
Reference in New Issue
Block a user