private async Task PublishToEventChannel(GraphQLObjectTypeFieldInfo fieldInfo, object result) { if (!string.IsNullOrEmpty(fieldInfo?.Channel) && this.context.OperationType == OperationType.Mutation) { await this.context.Schema?.SubscriptionType?.EventBus?.Publish(result, fieldInfo.Channel); } }
private GraphQLFieldInfo GetIntrospectedSchemaField() { return(GraphQLObjectTypeFieldInfo.CreateResolverFieldInfo( "__schema", (Expression <Func <IntrospectedSchemaType> >)(() => this.Schema.IntrospectedSchema), "Access the current type schema of this server.")); }
private GraphQLFieldInfo GetIntrospectedTypeField() { return(GraphQLObjectTypeFieldInfo.CreateResolverFieldInfo( "__type", (Expression <Func <string, IntrospectedType> >)((string name) => this.Schema.IntrospectType(name)), "Request the type information of a single type.")); }
private void GetFieldsAndFragmentNames( GraphQLSelectionSet node, Dictionary <string, ICollection <NodeAndDefinitions> > nodeDefinitions, ICollection <string> fragmentNames, GraphQLBaseType parentType, string presumedParentName = null) { foreach (var selection in node.Selections) { switch (selection.Kind) { case ASTNodeKind.Field: var fieldSelection = selection as GraphQLFieldSelection; var fieldName = fieldSelection.Name.Value; GraphQLObjectTypeFieldInfo fieldDefinition = null; if (parentType is GraphQLComplexType) { fieldDefinition = ((GraphQLComplexType)parentType).GetFieldInfo(fieldName); } var responseName = fieldSelection.Alias != null ? fieldSelection.Alias.Value : fieldName; if (!nodeDefinitions.ContainsKey(responseName)) { nodeDefinitions.Add(responseName, new List <NodeAndDefinitions>()); } nodeDefinitions[responseName].Add(new NodeAndDefinitions() { PresumedParentName = presumedParentName, ParentType = parentType, Selection = fieldSelection, FieldDefinition = fieldDefinition }); break; case ASTNodeKind.FragmentSpread: fragmentNames.Add(((GraphQLFragmentSpread)selection).Name.Value); break; case ASTNodeKind.InlineFragment: var inlineFragment = selection as GraphQLInlineFragment; var typeCondition = inlineFragment.TypeCondition; var inlineFragmentType = typeCondition != null ? this.SchemaRepository.GetSchemaOutputTypeByName(typeCondition.Name.Value) : parentType; this.GetFieldsAndFragmentNames( inlineFragment.SelectionSet, nodeDefinitions, fragmentNames, inlineFragmentType, typeCondition?.Name?.Value); break; } } }
private object ResolveField(GraphQLObjectTypeFieldInfo fieldInfo, IList <GraphQLArgument> arguments, object parent) { if (fieldInfo == null) { return(null); } if (fieldInfo.IsResolver) { return(this.ProcessField(this.InvokeWithArguments(arguments, fieldInfo.Lambda))); } return(this.ProcessField(fieldInfo.Lambda.Compile().DynamicInvoke(new object[] { parent }))); }
private async Task <object> TryResolveField( GraphQLFieldSelection selection, GraphQLObjectTypeFieldInfo fieldInfo, IList <GraphQLArgument> arguments, object parent) { try { return(await this.ResolveField(fieldInfo, arguments, parent)); } catch (TargetInvocationException ex) { var aliasOrName = selection.Alias?.Value ?? selection.Name.Value; var orderedPath = this.ReorderPath(this.path); var exception = new GraphQLException(ex.InnerException); var locatedException = GraphQLException.LocateException(exception, new[] { selection }, orderedPath.Append(aliasOrName)); this.Errors.Add(locatedException); return(await this.CompleteValue(null, fieldInfo.SystemType, selection, arguments, this.path)); } }
private async Task <object> ResolveField( GraphQLObjectTypeFieldInfo fieldInfo, IList <GraphQLArgument> arguments, object parent) { if (fieldInfo == null) { return(null); } if (fieldInfo.IsResolver) { var resolverResult = await this.InvokeWithArguments(arguments, fieldInfo.Lambda); return(this.ProcessField(resolverResult)); } var accessorResult = fieldInfo.Lambda.Compile().DynamicInvoke(new object[] { parent }); accessorResult = await this.HandleAsyncTaskIfAsync(accessorResult); return(this.ProcessField(accessorResult)); }
private Type GetResultType( GraphQLComplexType type, GraphQLObjectTypeFieldInfo fieldInfo, object result) { return(fieldInfo?.SystemType ?? result?.GetType()); }