private Fragment parseInlineFragment() throws EGraphQLException, IOException { Fragment result = new Fragment(); if (hasName("on")) { consumeName("on"); result.setTypeCondition(consumeName()); } parseFragmentInner(result); return result; }
private Fragment parseFragment() throws EGraphQLException, IOException { Fragment result = new Fragment(); result.setName(consumeName()); consumeName("on"); result.setTypeCondition(consumeName()); parseFragmentInner(result); 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 processVariables(Operation op) throws EGraphQLException { for (Variable varRef : op.getVariables()) { Argument varDef = null; for (Argument v : graphQL.getVariables()) if (v.getName().equals(varRef.getName())) varDef = v; if (varDef != null) workingVariables.put(varRef.getName(), varDef); // todo: check type? else if (varRef.getDefaultValue() != null) workingVariables.put(varRef.getName(), new Argument(varRef.getName(), varRef.getDefaultValue())); else throw new EGraphQLException("No value found for variable "); } }
public void valuesFromNode(JsonElement json) throws EGraphQLException { if (json instanceof JsonPrimitive && ((JsonPrimitive) json).isString()) values.add(new StringValue(((JsonPrimitive)json).getAsString())); else if (json instanceof JsonPrimitive && ((JsonPrimitive) json).isNumber()) values.add(new NumberValue(((JsonPrimitive)json).getAsString())); else if (json instanceof JsonPrimitive && ((JsonPrimitive) json).isBoolean()) values.add(new NameValue(((JsonPrimitive)json).getAsBoolean())); else if (json instanceof JsonObject) values.add(new ObjectValue((JsonObject) json)); else if (json instanceof JsonArray) { for (JsonElement v : (JsonArray) json) valuesFromNode(v); } else throw new EGraphQLException("Unexpected JSON type for \""+name+"\": "+json.getClass().getName()); }
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 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 void parseFragmentInner(Fragment fragment) throws EGraphQLException, IOException { while (hasPunctuation("@")) fragment.getDirectives().add(parseDirective()); consumePunctuation("{"); do fragment.getSelectionSet().add(parseSelection()); while (!hasPunctuation("}")); consumePunctuation("}"); }
private FragmentSpread parseFragmentSpread() throws EGraphQLException, IOException { FragmentSpread result = new FragmentSpread(); result.setName(consumeName()); while (hasPunctuation("@")) result.getDirectives().add(parseDirective()); return result; }
private void processSearch(ObjectValue target, List<Selection> selection, boolean inheritedList, String suffix) throws EGraphQLException, FHIRException { for (Selection sel : selection) { if ((sel.getField() == null)) throw new EGraphQLException("Only field selections are allowed in this context"); checkNoDirectives(sel.getField().getDirectives()); if ((isResourceName(sel.getField().getName(), ""))) processSearchSingle(target, sel.getField(), inheritedList, suffix); else if ((isResourceName(sel.getField().getName(), "List"))) processSearchSimple(target, sel.getField(), inheritedList, suffix); else if ((isResourceName(sel.getField().getName(), "Connection"))) processSearchFull(target, sel.getField(), inheritedList, suffix); } }
private void processPrimitive(Argument arg, Base value) { String s = value.fhirType(); if (s.equals("integer") || s.equals("decimal") || s.equals("unsignedInt") || s.equals("positiveInt")) arg.addValue(new NumberValue(value.primitiveValue())); else if (s.equals("boolean")) arg.addValue(new NameValue(value.primitiveValue())); else arg.addValue(new StringValue(value.primitiveValue())); }
public static Package parse(String source) throws IOException, EGraphQLException, EGraphEngine { Parser self = new Parser(); self.reader = new StringReader(source); self.next(); Document doc = self.parseDocument(); return new Package(doc); }
private String consumeName() throws EGraphQLException, IOException { if (lexType != LexType.gqlltName) throw new EGraphQLException("Found \""+token.toString()+"\" expecting a name"); String result = token.toString(); next(); return result; }
public void write(StringBuilder b, int indent) throws EGraphEngine { throw new EGraphEngine("Cannot write a variable to JSON"); }
public Argument(String name, JsonElement json) throws EGraphQLException { super(); this.name = name; valuesFromNode(json); } public String getName() {
private ArgumentListStatus listStatus(Field field, boolean isList) { if (field.hasDirective("singleton")) return ArgumentListStatus.SINGLETON; else if (isList) return ArgumentListStatus.REPEATING; else return ArgumentListStatus.NOT_SPECIFIED; }
public boolean hasValue(String value) { for (Value v : values ) if (v.isValue(value)) return true; return false; }
public static Package parse(InputStream source) throws IOException, EGraphQLException, EGraphEngine { Parser self = new Parser(); self.reader = new InputStreamReader(source); self.next(); Document doc = self.parseDocument(); return new Package(doc); }
private void consumePunctuation(String punc) throws EGraphQLException, IOException { if (lexType != LexType.gqlltPunctuation) throw new EGraphQLException("Found \""+token.toString()+"\" expecting \""+punc+"\""); if (!token.toString().equals(punc)) throw new EGraphQLException("Found \""+token.toString()+"\" expecting \""+punc+"\""); next(); }
private void consumeName(String name) throws EGraphQLException, IOException{ if (lexType != LexType.gqlltName) throw new EGraphQLException("Found \""+token.toString()+"\" expecting a name"); if (!token.toString().equals(name)) throw new EGraphQLException("Found \""+token.toString()+"\" expecting \""+name+"\""); next(); }