예제 #1
0
 public PossibleSelections(SelectionInfo returnType)
 {
     ReturnType = returnType;
     Variants   = new List <SelectionInfo> {
         returnType
     };
 }
예제 #2
0
 public PossibleSelections(
     SelectionInfo returnType,
     IReadOnlyList <SelectionInfo> variants)
 {
     ReturnType = returnType;
     Variants   = variants;
 }
예제 #3
0
        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);
        }