* Initial GraphQL implementation This is the bare minimum amount of code to make graphql work. Turns out it's pretty easy to add support for other languages :) * Fixing support for `graphql` parsing There was a few structural changes with the addition of CSS and Typescript that we had to take into account. * Fixing file glob, adding `graphql` to yarn.lock * Removing extraneous file * Adding `graphql` parser, style changes * Splitting out graphql printer * Removing merge conflict * Fixing yarn.lock * Addressing code review, using `createError` * Adding release config * Using exact version * Removing destructuring
27 lines
627 B
JavaScript
27 lines
627 B
JavaScript
"use strict";
|
|
|
|
const createError = require("./parser-create-error");
|
|
|
|
function parse(text) {
|
|
// Inline the require to avoid loading all the JS if we don't use it
|
|
const parser = require("graphql/language");
|
|
try {
|
|
const ast = parser.parse(text);
|
|
return ast;
|
|
} catch (error) {
|
|
const GraphQLError = require("graphql/error").GraphQLError;
|
|
if (error instanceof GraphQLError) {
|
|
throw createError(error.message, {
|
|
start: {
|
|
line: error.locations[0].line,
|
|
column: error.locations[0].column
|
|
}
|
|
});
|
|
} else {
|
|
throw error;
|
|
}
|
|
}
|
|
}
|
|
|
|
module.exports = parse;
|