public GraphQlMainExecution(IGraphQlDocument document, __SchemaContainer schema, IGraphQlOutput output, Object topLevelObject, string operationName, String vars) : base(document, schema) { this.TopLevelObject = topLevelObject; this.output = output; GetTypeFunc = schema.GetType; var operation = GetTopLevelOperation(operationName); var variables = new Dictionary <string, Object>(); // not parsed variables yet output.PushObject("data"); ExecuteSelectionSet(new ModifiableSelectionSet(operation.selectionSet()), ExtractAppropriate__TypeForOperation(schema.__schema, operation), this.ExtractAppropriateObjectForOperation(topLevelObject, operation), variables); output.Pop(); }
void CompleteValue(__Type fieldType, GraphQLParser.FieldContext field, List <GraphQLParser.FieldContext> fields, Object result, Dictionary <string, Object> variableValues, bool assertNotNull = false, Context context = Context.Object) { if (fieldType.kind == __TypeKind.NON_NULL) { var innerType = fieldType.ofType; CompleteValue(innerType, field, fields, result, variableValues, true); } else if (result == null && assertNotNull) { Error($"Null or empty value was found on non null field", field); } else if (fieldType.kind == __TypeKind.LIST) { if (result != null && TypeCheck.IsEnumerableType(result.GetType()) == false) { Error($"Did not find list type for {field.fieldName().GetText()} - found {result.GetType().Name}", field); } var innerType = fieldType.ofType; output.PushArray(field.fieldName().GetText()); if (result != null) { foreach (var c in (IEnumerable)result) { if (field.fieldName().GetText() == "types" && IsSchemaQuery && c is __Type && ((__Type)c).name.StartsWith("__")) { continue; } CompleteValue(innerType, field, fields, c, variableValues, false, Context.List); } } output.Pop(); } else if (fieldType.kind == __TypeKind.SCALAR || fieldType.kind == __TypeKind.ENUM) { CoerceDotNetValue(fieldType, field, result, context); } else if (fieldType.kind == __TypeKind.OBJECT || fieldType.kind == __TypeKind.UNION || fieldType.kind == __TypeKind.INTERFACE) { if (fieldType.kind == __TypeKind.OBJECT || fieldType.kind == __TypeKind.UNION) { var objectType = fieldType; var subSelectionSet = MergeSelectionSets(fields); if (context == Context.Object) { if (result == null) { output.AddScalarProperty(field.fieldName().GetText(), null); } else { output.PushObject(field.fieldName().GetText()); ExecuteSelectionSet(subSelectionSet, objectType, result, variableValues); } } else if (context == Context.List) { if (result != null) { output.PushObject(); ExecuteSelectionSet(subSelectionSet, objectType, result, variableValues); } } if (result != null) { output.Pop(); } } else { Error($"Interface and Union not yet supported", field); } } else { Error($"Unexpected fieldType - {fieldType.kind}", field); } }