public IGraphQlDocument Validate(Type queryType) { if (custom == null) { custom = new GraphQlCustomiseSchema(); } try { schema = GraphQlSchemaLoader.GetSchema(queryType); if (schema == null) { schema = GraphQlSchemaLoader.InitializeSchema(queryType, custom); } var z = new GraphQlMainValidation(this, schema); } catch (GraphQlException e) { validation_errors = true; output = new GraphQlJObject(); output.AddException(e); } catch (Exception e) { validation_errors = true; output = new GraphQlJObject(); output.AddException(new GraphQlException(e, 0, 0)); } return(this); }
public static __SchemaContainer InitializeSchema(Type root, GraphQlCustomiseSchema custom) { if (cached.ContainsKey(root) == false) { var queryAttribute = root.GetProperties() .FirstOrDefault(x => x.GetCustomAttribute(typeof(GraphQlTopLevelQueryAttribute)) != null); if (queryAttribute == null) { throw new Exception( $"Top Level query - {root.Name} - must contain a public property with '[GRaphQlQuery]' as attribute - to indicate top level query ... if mutations are required then must include [GraphQlMutations] attribute on a different property"); } var queryType = root.GetProperties().Where(x => x.GetCustomAttribute <GraphQlTopLevelQueryAttribute>() != null) .Select(x => x.PropertyType).First(); var mutationAttribute = root.GetProperties() .FirstOrDefault(x => x.GetCustomAttribute(typeof(GraphQlMutationsAttribute)) != null); Type mutationType = null; if (mutationAttribute == null) { L.Trace($"[GraphQlMutation] attribute on {root.Name} not found ... continuing"); } else { mutationType = root.GetProperties() .Where(x => x.GetCustomAttribute <GraphQlMutationsAttribute>() != null) .Select(x => x.PropertyType).First(); } var types = new Dictionary <Type, __Type>(); var __queryType = new __Type(queryType, types, custom); __SchemaContainer schemaContainer = null; if (mutationType == null) { schemaContainer = new __SchemaContainer(new __Schema(__queryType)); } else { var __mutationType = new __Type(mutationType, types, custom); schemaContainer = new __SchemaContainer(new __Schema(__queryType, __mutationType)); } var foo = new[] { typeof(__SchemaContainer) }.Select(x => new __Type(x, types, custom)) .ToArray(); schemaContainer.__schema.types = types.Values.Where(SchemaTypeFilter).ToList(); cached[root] = schemaContainer; } return(cached[root]); }
public GraphQlMainValidation(IGraphQlDocument doc, __SchemaContainer schema) : base(doc, schema) { OperationNameUniqueness(); LoneAnonymousOperation(); FragmentNameUniqueness(); FieldSelectionMatchFragments(); OperationSelectionMatch(); FieldSelectionMerging(); }
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(); }
protected GraphQlMainBase(IGraphQlDocument document, __SchemaContainer schema) { this.schema = schema; this.documentContext = ((GraphQlDocument)document).GetDocumentContext(); }