コード例 #1
0
    internal ConnectionType(ITypeReference nodeType, bool withTotalCount)
    {
        if (nodeType is null)
        {
            throw new ArgumentNullException(nameof(nodeType));
        }

        DependantFactoryTypeReference edgeType =
            TypeReference.Create(
                ContextDataKeys.EdgeType,
                nodeType,
                _ => new EdgeType(nodeType),
                TypeContext.Output);

        Definition = CreateTypeDefinition(withTotalCount);
        Definition.Dependencies.Add(new(nodeType));
        Definition.Dependencies.Add(new(edgeType));
        Definition.NeedsNameCompletion = true;

        Definition.Configurations.Add(
            new CompleteConfiguration(
                (c, d) =>
        {
            IType type     = c.GetType <IType>(nodeType);
            ConnectionName = type.NamedType().Name;

            var definition = (ObjectTypeDefinition)d;
            ObjectFieldDefinition edges = definition.Fields.First(IsEdgesField);
            ObjectFieldDefinition nodes = definition.Fields.First(IsNodesField);

            definition.Name = NameHelper.CreateConnectionName(ConnectionName);
            edges.Type      = TypeReference.Parse(
                $"[{NameHelper.CreateEdgeName(ConnectionName)}!]",
                TypeContext.Output);

            nodes.Type = TypeReference.Parse(
                $"[{type.Print()}]",
                TypeContext.Output);
        },
                Definition,
                ApplyConfigurationOn.Naming,
                nodeType,
                TypeDependencyKind.Named));
        Definition.Configurations.Add(
            new CompleteConfiguration(
                (c, _) =>
        {
            EdgeType = c.GetType <IEdgeType>(edgeType);
        },
                Definition,
                ApplyConfigurationOn.Completion));
    }
コード例 #2
0
    internal ConnectionType(
        NameString connectionName,
        ITypeReference nodeType,
        bool withTotalCount)
    {
        if (nodeType is null)
        {
            throw new ArgumentNullException(nameof(nodeType));
        }

        ConnectionName = connectionName.EnsureNotEmpty(nameof(connectionName));
        NameString edgeTypeName = NameHelper.CreateEdgeName(connectionName);

        SyntaxTypeReference edgesType =
            TypeReference.Parse(
                $"[{edgeTypeName}!]",
                TypeContext.Output,
                factory: _ => new EdgeType(connectionName, nodeType));

        Definition      = CreateTypeDefinition(withTotalCount, edgesType);
        Definition.Name = NameHelper.CreateConnectionName(connectionName);
        Definition.Dependencies.Add(new(nodeType));
        Definition.Configurations.Add(
            new CompleteConfiguration(
                (c, d) =>
        {
            var definition = (ObjectTypeDefinition)d;
            ObjectFieldDefinition nodes = definition.Fields.First(IsNodesField);
            nodes.Type = TypeReference.Parse(
                $"[{c.GetType<IType>(nodeType).Print()}]",
                TypeContext.Output);
        },
                Definition,
                ApplyConfigurationOn.Naming,
                nodeType,
                TypeDependencyKind.Named));
        Definition.Configurations.Add(
            new CompleteConfiguration(
                (c, _) => EdgeType = c.GetType <IEdgeType>(TypeReference.Create(edgeTypeName)),
                Definition,
                ApplyConfigurationOn.Completion));
    }