public void Optimize(SelectionSetOptimizerContext context) { if (context.FieldContext.TryPeek(out IObjectField field) && field.Name.Equals("bar")) { IObjectField baz = context.TypeContext.Fields["baz"]; FieldNode bazSelection = Utf8GraphQLParser.Syntax.ParseField("baz { text }"); FieldDelegate bazPipeline = context.CompileResolverPipeline(baz, bazSelection); var compiledSelection = new PreparedSelection( context.TypeContext, baz, bazSelection, bazPipeline, internalSelection: true); context.Fields[compiledSelection.ResponseName] = compiledSelection; } }
private void ResolveFieldSelection( ObjectType typeContext, FieldNode selection, SelectionIncludeCondition?includeCondition, IDictionary <ISelectionNode, SelectionIncludeCondition> includeConditionLookup, IDictionary <string, PreparedSelection> fields, bool internalSelection) { NameString fieldName = selection.Name.Value; NameString responseName = selection.Alias is null ? selection.Name.Value : selection.Alias.Value; if (typeContext.Fields.TryGetField(fieldName, out ObjectField? field)) { if (fields.TryGetValue(responseName, out PreparedSelection? preparedSelection)) { preparedSelection.AddSelection(selection, includeCondition); } else { // if this is the first time we find a selection to this field we have to // create a new prepared selection. preparedSelection = new PreparedSelection( typeContext, field, selection, responseName: responseName, resolverPipeline: CreateFieldMiddleware(field, selection), arguments: CoerceArgumentValues(field, selection, responseName), includeCondition: includeCondition, internalSelection: internalSelection); fields.Add(responseName, preparedSelection); } if (includeCondition is { } && selection.SelectionSet is { })