public ISet <FieldDependency> GetFieldDependencies( DocumentNode document, SelectionSetNode selectionSet, INamedOutputType declaringType) { if (document == null) { throw new ArgumentNullException(nameof(document)); } if (selectionSet == null) { throw new ArgumentNullException(nameof(selectionSet)); } if (declaringType == null) { throw new ArgumentNullException(nameof(declaringType)); } var context = Context.New(declaringType, GetFragments(document)); VisitSelectionSet(selectionSet, context); return(context.Dependencies); }
public FieldCollectionResult CollectFields( INamedOutputType type, SelectionSetNode selectionSet, Path path) { if (type == null) { throw new ArgumentNullException(nameof(type)); } if (selectionSet == null) { throw new ArgumentNullException(nameof(selectionSet)); } var fields = new OrderedDictionary <string, FieldSelection>(); var root = new FragmentNode(); CollectFields(type, selectionSet, path, fields, root); return(new FieldCollectionResult( type, selectionSet, fields.Values.ToList(), root.Children)); }
private SelectionInfo CollectFieldsInternal( INamedOutputType type, SelectionSetNode selectionSet, Path path) { if (type == null) { throw new ArgumentNullException(nameof(type)); } if (selectionSet == null) { throw new ArgumentNullException(nameof(selectionSet)); } var fields = new OrderedDictionary <string, FieldSelection>(); var fragments = new List <IFragmentNode>(); CollectFields(type, selectionSet, path, fields, fragments); return(new SelectionInfo( type, selectionSet, fields.Values.ToList(), fragments)); }
private Context(Context context, INamedOutputType typeContext) { Dependencies = context.Dependencies; TypeContext = typeContext; Fragments = context.Fragments; FragmentPath = context.FragmentPath; }
public void DiscoverInputArgumentTypes() { // arrange // act ISchema schema = Schema.Create(c => { c.RegisterQueryType <QueryFieldArgument>(); }); // assert INamedOutputType foo = schema.GetType <INamedOutputType>("Foo"); Assert.NotNull(foo); INamedOutputType bar = schema.GetType <INamedOutputType>("Bar"); Assert.NotNull(foo); INamedInputType fooInput = schema.GetType <INamedInputType>("FooInput"); Assert.NotNull(fooInput); INamedInputType barInput = schema.GetType <INamedInputType>("BarInput"); Assert.NotNull(barInput); }
protected override void OnCompleteType( ITypeInitializationContext context) { EntityType = context.GetType <T>( new TypeReference(typeof(T))); base.OnCompleteType(context); }
private Context( INamedOutputType typeContext, IDictionary <string, FragmentDefinitionNode> fragments) { Dependencies = new HashSet <FieldDependency>(); TypeContext = typeContext; Fragments = fragments; FragmentPath = ImmutableHashSet <string> .Empty; }
public override MaxComplexityVisitorContext SetTypeContext( INamedOutputType typeContext) { var newContext = new MaxComplexityWithMultipliersVisitorContext(this); newContext.TypeContext = typeContext; return(newContext); }
public PossibleSelections CollectFields( INamedOutputType type, SelectionSetNode selectionSet, Path path) { if (!_cache.TryGetValue(type, out SelectionCache? selectionCache)) { selectionCache = new SelectionCache(); _cache.Add(type, selectionCache); } if (!selectionCache.TryGetValue( selectionSet, out PossibleSelections? possibleSelections)) { SelectionInfo returnType = CollectFieldsInternal(type, selectionSet, path); if (type.IsAbstractType()) { var list = new List <SelectionInfo>(); bool singleModelShape = true; foreach (ObjectType objectType in _schema.GetPossibleTypes(type)) { SelectionInfo objectSelection = CollectFieldsInternal(objectType, selectionSet, path); list.Add(objectSelection); if (!FieldSelectionsAreEqual( returnType.Fields, objectSelection.Fields)) { singleModelShape = false; } } if (!singleModelShape) { possibleSelections = new PossibleSelections(returnType, list); } } if (possibleSelections is null) { possibleSelections = new PossibleSelections(returnType); } selectionCache.Add(selectionSet, possibleSelections); } return(possibleSelections); }
public ExtractedField ExtractField( NameString sourceSchema, DocumentNode document, OperationDefinitionNode operation, IFieldSelection selection, INamedOutputType declaringType) { if (document == null) { throw new ArgumentNullException(nameof(document)); } if (operation == null) { throw new ArgumentNullException(nameof(operation)); } if (selection == null) { throw new ArgumentNullException(nameof(selection)); } if (declaringType == null) { throw new ArgumentNullException(nameof(declaringType)); } sourceSchema.EnsureNotEmpty(nameof(sourceSchema)); var context = new Context( sourceSchema, declaringType, document, operation); var syntaxNodes = new List <FieldNode>(); foreach (FieldNode syntaxNode in selection.SyntaxNodes) { FieldNode field = RewriteField(syntaxNode, context); if (selection.Field.Type.NamedType().IsLeafType() || (field.SelectionSet is not null && field.SelectionSet.Selections.Count > 0)) { syntaxNodes.Add(field); } } return(new ExtractedField( syntaxNodes, context.Variables.Values.ToList(), context.Fragments.Values.ToList())); }
public Context( NameString schema, INamedOutputType typeContext, DocumentNode document, OperationDefinitionNode operation) { Schema = schema; Variables = new Dictionary <string, VariableDefinitionNode>(); Document = document; Operation = operation; TypeContext = typeContext; Fragments = new Dictionary <string, FragmentDefinitionNode>(); FragmentPath = ImmutableHashSet <string> .Empty; }
private void ResolveFields( INamedOutputType type, ISelectionNode selection, Path path, IDictionary <string, FieldSelection> fields, ICollection <IFragmentNode> fragments) { if (selection is FieldNode fs && type is IComplexOutputType ct) { ResolveFieldSelection( ct, fs, path, fields); }
private void CollectFields( INamedOutputType type, SelectionSetNode selectionSet, Path path, IDictionary <string, FieldSelection> fields, ICollection <IFragmentNode> fragments) { foreach (ISelectionNode selection in selectionSet.Selections) { ResolveFields( type, selection, path, fields, fragments); } }
private Fragment CreateFragment( INamedOutputType parentType, InlineFragmentNode inlineFragment) { INamedType type; if (inlineFragment.TypeCondition == null) { type = parentType; } else { type = _schema.GetType <INamedType>( inlineFragment.TypeCondition.Name.Value); } return(new Fragment(type.Name, FragmentKind.Inline, type, inlineFragment.SelectionSet)); }
public ExtractedField ExtractField( NameString sourceSchema, DocumentNode document, OperationDefinitionNode operation, FieldNode field, INamedOutputType declaringType) { if (document == null) { throw new ArgumentNullException(nameof(document)); } if (operation == null) { throw new ArgumentNullException(nameof(operation)); } if (field == null) { throw new ArgumentNullException(nameof(field)); } if (declaringType == null) { throw new ArgumentNullException(nameof(declaringType)); } sourceSchema.EnsureNotEmpty(nameof(sourceSchema)); var context = new Context( sourceSchema, declaringType, document, operation); FieldNode rewrittenField = RewriteField(field, context); return(new ExtractedField( rewrittenField, context.Variables.Values.ToList(), context.Fragments.Values.ToList())); }
public Fragment GetFragment( INamedOutputType parentType, InlineFragmentNode inlineFragment) { if (parentType == null) { throw new ArgumentNullException(nameof(parentType)); } if (inlineFragment == null) { throw new ArgumentNullException(nameof(inlineFragment)); } string fragmentName = CreateInlineFragmentName(inlineFragment); if (!_fragments.TryGetValue(fragmentName, out Fragment? fragment)) { fragment = CreateFragment(parentType, inlineFragment); _fragments[fragmentName] = fragment; } return(fragment); }
public PossibleSelections CollectFields( INamedOutputType type, SelectionSetNode selectionSet, Path path) => _collector.CollectFields(type, selectionSet, path);
public Context SetTypeContext(INamedOutputType type) { return(new Context(this, type)); }
public static Context New( INamedOutputType typeContext, IDictionary <string, FragmentDefinitionNode> fragments) { return(new Context(typeContext, fragments)); }