private void parseFragmentInner(Fragment fragment) throws EGraphQLException, IOException { while (hasPunctuation("@")) fragment.getDirectives().add(parseDirective()); consumePunctuation("{"); do fragment.getSelectionSet().add(parseSelection()); while (!hasPunctuation("}")); consumePunctuation("}"); }
private void parseOperationInner(Operation op) throws EGraphQLException, IOException { if (hasPunctuation("(")) { consumePunctuation("("); do op.getVariables().add(parseVariable()); while (!hasPunctuation(")")); consumePunctuation(")"); } while (hasPunctuation("@")) op.getDirectives().add(parseDirective()); if (hasPunctuation("{")) { consumePunctuation("{"); do op.getSelectionSet().add(parseSelection()); while (!hasPunctuation("}")); consumePunctuation("}"); } }
private Directive parseDirective() throws EGraphQLException, IOException { Directive result = new Directive(); consumePunctuation("@"); result.setName(consumeName()); if (hasPunctuation("(")) { consumePunctuation("("); do { result.getArguments().add(parseArgument()); } while (!hasPunctuation(")")); consumePunctuation(")"); } return result; }
private FragmentSpread parseFragmentSpread() throws EGraphQLException, IOException { FragmentSpread result = new FragmentSpread(); result.setName(consumeName()); while (hasPunctuation("@")) result.getDirectives().add(parseDirective()); return result; }
private Field parseField() throws EGraphQLException, IOException { Field result = new Field(); result.setName(consumeName()); result.setAlias(result.getName()); if (hasPunctuation(":")) { consumePunctuation(":"); result.setName(consumeName()); } if (hasPunctuation("(")) { consumePunctuation("("); while (!hasPunctuation(")")) result.getArguments().add(parseArgument()); consumePunctuation(")"); } while (hasPunctuation("@")) result.getDirectives().add(parseDirective()); if (hasPunctuation("{")) { consumePunctuation("{"); do { result.getSelectionSet().add(parseSelection()); } while (!hasPunctuation("}")); consumePunctuation("}"); } return result; }
private Value parseValue() throws EGraphQLException, IOException { Value result = null; switch (lexType) { case gqlltNull: throw new EGraphQLException("Attempt to read a value after reading off the } of the GraphQL statement"); case gqlltName: result = new NameValue(token.toString()); break; case gqlltPunctuation: if (hasPunctuation("$")) { consumePunctuation("$"); result = new VariableValue(token.toString()); } else if (hasPunctuation("{")) { consumePunctuation("{"); ObjectValue obj = new ObjectValue(); while (!hasPunctuation("}")) obj.getFields().add(parseArgument()); result = obj; } else throw new EGraphQLException("Attempt to read a value at \""+token.toString()+"\""); break; case gqlltString: result = new StringValue(token.toString()); break; case gqlltNumber: result = new NumberValue(token.toString()); break; } next(); return result; }
private Argument parseArgument() throws EGraphQLException, IOException { Argument result = new Argument(); result.setName(consumeName()); consumePunctuation(":"); if (hasPunctuation("[")) { result.setListStatus(ArgumentListStatus.REPEATING); consumePunctuation("["); while (!hasPunctuation("]")) result.getValues().add(parseValue()); consumePunctuation("]"); } else result.getValues().add(parseValue()); return result; }
private Selection parseSelection() throws EGraphQLException, IOException { Selection result = new Selection(); if (hasPunctuation("...")) { consumePunctuation("..."); if (hasName() && !token.toString().equals("on")) result.setFragmentSpread(parseFragmentSpread()); else result.setInlineFragment(parseInlineFragment()); } else result.setField(parseField()); return result; }
private Variable parseVariable() throws EGraphQLException, IOException { Variable result = new Variable(); consumePunctuation("$"); result.setName(consumeName()); consumePunctuation(":"); result.setTypeName(consumeName()); if (hasPunctuation("=")) { consumePunctuation("="); result.setDefaultValue(parseValue()); } return result; }
private void parseFragmentInner(Fragment fragment) throws EGraphQLException, IOException { while (hasPunctuation("@")) fragment.getDirectives().add(parseDirective()); consumePunctuation("{"); do fragment.getSelectionSet().add(parseSelection()); while (!hasPunctuation("}")); consumePunctuation("}"); }
private void parseOperationInner(Operation op) throws EGraphQLException, IOException { if (hasPunctuation("(")) { consumePunctuation("("); do op.getVariables().add(parseVariable()); while (!hasPunctuation(")")); consumePunctuation(")"); } while (hasPunctuation("@")) op.getDirectives().add(parseDirective()); if (hasPunctuation("{")) { consumePunctuation("{"); do op.getSelectionSet().add(parseSelection()); while (!hasPunctuation("}")); consumePunctuation("}"); } }
private Directive parseDirective() throws EGraphQLException, IOException { Directive result = new Directive(); consumePunctuation("@"); result.setName(consumeName()); if (hasPunctuation("(")) { consumePunctuation("("); do { result.getArguments().add(parseArgument()); } while (!hasPunctuation(")")); consumePunctuation(")"); } return result; }
private FragmentSpread parseFragmentSpread() throws EGraphQLException, IOException { FragmentSpread result = new FragmentSpread(); result.setName(consumeName()); while (hasPunctuation("@")) result.getDirectives().add(parseDirective()); return result; }
private Field parseField() throws EGraphQLException, IOException { Field result = new Field(); result.setName(consumeName()); result.setAlias(result.getName()); if (hasPunctuation(":")) { consumePunctuation(":"); result.setName(consumeName()); } if (hasPunctuation("(")) { consumePunctuation("("); while (!hasPunctuation(")")) result.getArguments().add(parseArgument()); consumePunctuation(")"); } while (hasPunctuation("@")) result.getDirectives().add(parseDirective()); if (hasPunctuation("{")) { consumePunctuation("{"); do { result.getSelectionSet().add(parseSelection()); } while (!hasPunctuation("}")); consumePunctuation("}"); } return result; }
private Value parseValue() throws EGraphQLException, IOException { Value result = null; switch (lexType) { case gqlltNull: throw new EGraphQLException("Attempt to read a value after reading off the } of the GraphQL statement"); case gqlltName: result = new NameValue(token.toString()); break; case gqlltPunctuation: if (hasPunctuation("$")) { consumePunctuation("$"); result = new VariableValue(token.toString()); } else if (hasPunctuation("{")) { consumePunctuation("{"); ObjectValue obj = new ObjectValue(); while (!hasPunctuation("}")) obj.getFields().add(parseArgument()); result = obj; } else throw new EGraphQLException("Attempt to read a value at \""+token.toString()+"\""); break; case gqlltString: result = new StringValue(token.toString()); break; case gqlltNumber: result = new NumberValue(token.toString()); break; } next(); return result; }
private Argument parseArgument() throws EGraphQLException, IOException { Argument result = new Argument(); result.setName(consumeName()); consumePunctuation(":"); if (hasPunctuation("[")) { result.setListStatus(ArgumentListStatus.REPEATING); consumePunctuation("["); while (!hasPunctuation("]")) result.getValues().add(parseValue()); consumePunctuation("]"); } else result.getValues().add(parseValue()); return result; }
private Selection parseSelection() throws EGraphQLException, IOException { Selection result = new Selection(); if (hasPunctuation("...")) { consumePunctuation("..."); if (hasName() && !token.toString().equals("on")) result.setFragmentSpread(parseFragmentSpread()); else result.setInlineFragment(parseInlineFragment()); } else result.setField(parseField()); return result; }
private Variable parseVariable() throws EGraphQLException, IOException { Variable result = new Variable(); consumePunctuation("$"); result.setName(consumeName()); consumePunctuation(":"); result.setTypeName(consumeName()); if (hasPunctuation("=")) { consumePunctuation("="); result.setDefaultValue(parseValue()); } return result; }