private object GetDefinitionAndExecuteField(GraphQLObjectType type, GraphQLFieldSelection selection) { var arguments = this.GetArgumentsFromSelection(selection); var fieldInfo = this.GetFieldInfo(type, selection); var resolvedValue = this.ResolveField(fieldInfo, arguments, this.parent); return(this.CompleteValue(resolvedValue, selection, arguments)); }
public DefinitionTests() { var BlogImage = new GraphQLObjectType("Image", fields: new GraphQLFieldDefinitionMap( new [] { new GraphQLFieldDefinition("url") {Type = Scalars.GraphQLString,}, new GraphQLFieldDefinition("width") {Type = Scalars.GraphQLInt,}, new GraphQLFieldDefinition("height") {Type = Scalars.GraphQLInt,}, }) ); var BlogAuthor = new GraphQLObjectType("Author", fields: new GraphQLFieldDefinitionMap( new [] { new GraphQLFieldDefinition("id") {Type = Scalars.GraphQLString,}, new GraphQLFieldDefinition("name") {Type = Scalars.GraphQLString,}, new GraphQLFieldDefinition("pic", args: new [] { new GraphQLArgument("width", Scalars.GraphQLInt), new GraphQLArgument("height", Scalars.GraphQLInt), }, type: Scalars.GraphQLString), new GraphQLFieldDefinition("recentArticle", type: BlogImage), })); var BlogArticle = new GraphQLObjectType("Article", fields: new GraphQLFieldDefinitionMap( new [] { new GraphQLFieldDefinition("id", type: Scalars.GraphQLString), new GraphQLFieldDefinition("isPublished", type: Scalars.GraphQLBoolean), new GraphQLFieldDefinition("author", type: BlogAuthor), new GraphQLFieldDefinition("title", type: Scalars.GraphQLString), new GraphQLFieldDefinition("body", type: Scalars.GraphQLString), })); var BlogQuery = new GraphQLObjectType("Query", fields: new GraphQLFieldDefinitionMap( new [] { new GraphQLFieldDefinition("article", args: new [] { new GraphQLArgument("id", Scalars.GraphQLString), }, type: BlogArticle), new GraphQLFieldDefinition("feed", type: new GraphQLList(BlogArticle)), })); var BlogMutation = new GraphQLObjectType("Mutation", fields: new GraphQLFieldDefinitionMap( new [] { new GraphQLFieldDefinition("writeArticle", type: BlogArticle), })); var ObjectType = new GraphQLObjectType("Object"); var InterfaceType = new GraphQLObjectType("Interface"); var UnionType = new GraphQLUnionType("Union", types: ImmutableArray.Create(new GraphQLObjectType())); }
public static IntrospectedType CreateForObject(GraphQLObjectType type, IIntrospector introspector, IObjectTypeTranslator typeObserver) { var introspectedType = new ComplexIntrospectedType(introspector, typeObserver); introspectedType.Name = type.Name; introspectedType.Description = type.Description; introspectedType.Kind = TypeKind.OBJECT; return(introspectedType); }
public Dictionary <string, IList <GraphQLFieldSelection> > CollectFields(GraphQLObjectType runtimeType, GraphQLSelectionSet selectionSet) { var fields = new Dictionary <string, IList <GraphQLFieldSelection> >(); foreach (var selection in selectionSet.Selections) { this.CollectFieldsInSelection(runtimeType, selection, fields); } return(fields); }
private void CollectFieldsInSelection(GraphQLObjectType runtimeType, ASTNode selection, Dictionary <string, IList <GraphQLFieldSelection> > fields) { switch (selection.Kind) { case ASTNodeKind.Field: this.CollectField((GraphQLFieldSelection)selection, fields); break; case ASTNodeKind.FragmentSpread: this.CollectFragmentSpreadFields(runtimeType, (GraphQLFragmentSpread)selection, fields); break; case ASTNodeKind.InlineFragment: this.CollectFragmentFields(runtimeType, (GraphQLInlineFragment)selection, fields); break; } }
private async Task <ExpandoObject> TryGetObject(FieldScope scope, GraphQLObjectType input, GraphQLFieldSelection selection, IEnumerable <object> path) { try { return(await scope.GetObject(this.context.FieldCollector.CollectFields(input, selection.SelectionSet))); } catch (GraphQLResolveException) { return(null); } }
private string PrintObject(GraphQLObjectType type) { var interfaces = this.schema.SchemaRepository.GetImplementingInterfaces(type); var implementedInterfaces = interfaces.Any() ? $" implements {string.Join(", ", interfaces.Select(e => e.Name))}" : string.Empty; return (PrintDescription(type) + $"type {type.Name}{implementedInterfaces} {{\n" + $"{this.PrintFields(type)}\n}}"); }
private bool DoesFragmentConditionMatch(GraphQLObjectType runtimeType, GraphQLInlineFragment fragment) { if (fragment.TypeCondition == null) { return(true); } if (fragment.TypeCondition.Name.Value == runtimeType.Name) { return(true); } return(false); }
private object CompleteObjectType( GraphQLObjectType input, GraphQLFieldSelection selection, IList <GraphQLArgument> arguments, object parentObject) { var scope = new FieldScope( this.typeTranslator, this.valueResolver, this.fieldCollector, input, parentObject); scope.arguments = arguments.ToList(); return(scope.GetObject(this.fieldCollector.CollectFields(input, selection.SelectionSet))); }
public FieldScope( ITypeTranslator typeTranslator, IValueResolver valueResolver, IFieldCollector fieldCollector, GraphQLObjectType type, object parent) { this.type = type; this.parent = parent; this.arguments = new List <GraphQLArgument>(); this.fieldCollector = fieldCollector; this.typeTranslator = typeTranslator; this.valueResolver = valueResolver; }
private void CollectFragmentFields(GraphQLObjectType runtimeType, GraphQLInlineFragment fragment, Dictionary <string, IList <GraphQLFieldSelection> > fields) { if (!this.ShouldIncludeNode(fragment.Directives)) { return; } if (!this.DoesFragmentConditionMatch(runtimeType, fragment)) { return; } this.CollectFields(runtimeType, fragment.SelectionSet) .ToList().ForEach(e => fields.Add(e.Key, e.Value)); }
private dynamic ComposeResultForType(GraphQLObjectType type, GraphQLSelectionSet selectionSet) { var variableResolver = new VariableResolver(this.variables, this.graphQLSchema.TypeTranslator, this.operation.VariableDefinitions); var valueResolver = new ValueResolver(variableResolver, this.graphQLSchema.TypeTranslator); var fieldCollector = new FieldCollector(this.fragments, valueResolver); var scope = new FieldScope( this.graphQLSchema.TypeTranslator, valueResolver, fieldCollector, type, null); return(scope.GetObject(fieldCollector.CollectFields(type, selectionSet))); }
private async Task <object> CompleteObjectType( GraphQLObjectType input, GraphQLFieldSelection selection, IList <GraphQLArgument> arguments, object parentObject, IEnumerable <object> path) { var aliasOrName = selection.Alias?.Value ?? selection.Name.Value; var scope = new FieldScope(this.context, input, parentObject, path.Append(aliasOrName), this.Errors) { arguments = arguments.ToList() }; return(await this.TryGetObject(scope, input, selection, path)); }
public object CreateObjectFromDynamic(GraphQLObjectType inputObjectType, ExpandoObject inputObject) { var systemType = this.GetType(inputObjectType); var fields = GetAccessorsFromType(inputObjectType); var inputObjectDictionary = (IDictionary <string, object>)inputObject; var resultObject = Activator.CreateInstance(systemType); foreach (var field in fields) { if (!inputObjectDictionary.ContainsKey(field.Name)) { continue; } this.AssignValueToField(inputObjectDictionary[field.Name], resultObject, field.Lambda); } return(resultObject); }
public void SetUp() { this.schema = new GraphQLSchema(); this.root = new QueryRootType(this.schema); }
public DefinitionTests() { var BlogImage = new GraphQLObjectType("Image", fields: new GraphQLFieldDefinitionMap( new [] { new GraphQLFieldDefinition("url") { Type = Scalars.GraphQLString, }, new GraphQLFieldDefinition("width") { Type = Scalars.GraphQLInt, }, new GraphQLFieldDefinition("height") { Type = Scalars.GraphQLInt, }, }) ); var BlogAuthor = new GraphQLObjectType("Author", fields: new GraphQLFieldDefinitionMap( new [] { new GraphQLFieldDefinition("id") { Type = Scalars.GraphQLString, }, new GraphQLFieldDefinition("name") { Type = Scalars.GraphQLString, }, new GraphQLFieldDefinition("pic", args: new [] { new GraphQLArgument("width", Scalars.GraphQLInt), new GraphQLArgument("height", Scalars.GraphQLInt), }, type: Scalars.GraphQLString), new GraphQLFieldDefinition("recentArticle", type: BlogImage), })); var BlogArticle = new GraphQLObjectType("Article", fields: new GraphQLFieldDefinitionMap( new [] { new GraphQLFieldDefinition("id", type: Scalars.GraphQLString), new GraphQLFieldDefinition("isPublished", type: Scalars.GraphQLBoolean), new GraphQLFieldDefinition("author", type: BlogAuthor), new GraphQLFieldDefinition("title", type: Scalars.GraphQLString), new GraphQLFieldDefinition("body", type: Scalars.GraphQLString), })); var BlogQuery = new GraphQLObjectType("Query", fields: new GraphQLFieldDefinitionMap( new [] { new GraphQLFieldDefinition("article", args: new [] { new GraphQLArgument("id", Scalars.GraphQLString), }, type: BlogArticle), new GraphQLFieldDefinition("feed", type: new GraphQLList(BlogArticle)), })); var BlogMutation = new GraphQLObjectType("Mutation", fields: new GraphQLFieldDefinitionMap( new [] { new GraphQLFieldDefinition("writeArticle", type: BlogArticle), })); var ObjectType = new GraphQLObjectType("Object"); var InterfaceType = new GraphQLObjectType("Interface"); var UnionType = new GraphQLUnionType("Union", types: ImmutableArray.Create(new GraphQLObjectType())); }
private static List <GraphQLObjectTypeFieldInfo> GetAccessorsFromType(GraphQLObjectType inputObjectType) { return(inputObjectType.GetFieldsInfo() .Where(e => e.IsResolver == false) .ToList()); }
private void CollectFragmentSpreadFields(GraphQLObjectType runtimeType, GraphQLFragmentSpread fragmentSpread, Dictionary <string, IList <GraphQLFieldSelection> > fields) { var fragment = this.fragments[fragmentSpread.Name.Value]; this.CollectFragmentFields(runtimeType, fragment, fields); }
private IntrospectedType IntrospectObjectType(GraphQLObjectType type) { return(IntrospectedType.CreateForObject(type, this, this.typeTranslator.GetObjectTypeTranslatorFor(type))); }
private GraphQLObjectTypeFieldInfo GetFieldInfo(GraphQLObjectType type, GraphQLFieldSelection selection) { var name = this.GetFieldName(selection); return(type.GetFieldInfo(name)); }
public void SetUp() { this.type = new GraphQLTestModelType(); }