Exemplo n.º 1
0
        private (IComplexGraphType edgeType, Field queryAstNode) StripRelayConnection(IComplexGraphType graphType, Field fieldAst)
        {
            var edgesType = (IComplexGraphType)graphType.GetField("edges").ResolvedType.GetNamedType();
            var edgeType  = (IComplexGraphType)edgesType.GetField("node").ResolvedType.GetNamedType();

            var field = fieldAst.SelectionSet.Selections
                        .OfType <Field>()
                        .FirstOrDefault(x => x.Name == "edges")
                        ?.SelectionSet.Selections.OfType <Field>()
                        .FirstOrDefault(x => x.Name == "node")
                        ?? fieldAst.SelectionSet.Selections
                        .OfType <Field>()
                        .FirstOrDefault(x => x.Name == "items")
                        ?? new Field();

            fieldAst = new Field(fieldAst.AliasNode, fieldAst.NameNode)
            {
                Arguments      = fieldAst.Arguments,
                Directives     = fieldAst.Directives,
                SelectionSet   = field.SelectionSet,
                SourceLocation = fieldAst.SourceLocation
            };

            return(edgeType, fieldAst);
        }
 public DelegateToFieldRule(
     IComplexGraphType graphType,
     string fieldName,
     string delegateFieldName,
     Func <TModel, TDelegateID> idGetter)
 {
     ResolvedType = graphType.GetField(fieldName).ResolvedType as IComplexGraphType;
     if (ResolvedType == null)
     {
         throw new Exception($"ResolvedType of an object authorized by {GetType().Name} must be an IComplexGraphType");
     }
     DelegateFieldName = delegateFieldName;
     IDGetter          = idGetter;
 }
Exemplo n.º 3
0
        private void HandleSelections(SqlTable parent, IComplexGraphType graphType, IEnumerable <ISelection> selections,
                                      int depth, IResolveFieldContext context)
        {
            foreach (var selection in selections)
            {
                switch (selection)
                {
                case Field fieldAst:
                    if (fieldAst.Name.StartsWith("__"))
                    {
                        continue;
                    }

                    var field = graphType.GetField(fieldAst.Name);
                    var node  = Convert(parent, fieldAst, field, graphType, ++depth, context);

                    switch (node)
                    {
                    case SqlColumnBase sqlColumn:
                        var fieldName = fieldAst.Alias ?? fieldAst.Name;
                        var existing  = parent.Columns.Any(x => x.FieldName == fieldName);

                        if (existing)
                        {
                            continue;
                        }

                        parent.Columns.Add(sqlColumn);
                        break;

                    case SqlTable sqlTable:
                        parent.Tables.Add(sqlTable);
                        break;

                    case SqlNoop _:
                        continue;

                    default:
                        throw new ArgumentOutOfRangeException(nameof(node), $"Unknown node type ${node.GetType()}");
                    }

                    break;

                case InlineFragment inlineFragment:
                {
                    var selectionNameOfType = inlineFragment.Type.Name;
                    var deferredType        = context.Schema.FindType(selectionNameOfType);

                    if (deferredType is IComplexGraphType complexGraphType)
                    {
                        HandleSelections(parent, complexGraphType,
                                         inlineFragment.SelectionSet.Selections, depth, context);
                    }

                    break;
                }

                case FragmentSpread fragmentSpread:
                {
                    var fragmentName        = fragmentSpread.Name;
                    var definition          = context.Fragments.FindDefinition(fragmentName);
                    var selectionNameOfType = definition.Type.Name;
                    var deferredType        = context.Schema.FindType(selectionNameOfType);

                    if (deferredType is IComplexGraphType complexGraphType)
                    {
                        HandleSelections(parent, complexGraphType,
                                         definition.SelectionSet.Selections, depth, context);
                    }

                    break;
                }

                default:
                    throw new ArgumentOutOfRangeException(nameof(selection), $"Unknown selection kind: {selection.GetType()}");
                }
            }
        }