Пример #1
0
        public static ISchema MakeExecutableSchemaWithIntrospection(
            SchemaBuilder builder,
            IResolverMap resolvers,
            ISubscriberMap subscribers = null,
            IReadOnlyDictionary <string, IValueConverter> converters        = null,
            IReadOnlyDictionary <string, CreateDirectiveVisitor> directives = null)
        {
            // add converters
            if (converters != null)
            {
                UseConverters(builder, converters);
            }

            builder.UseResolversAndSubscribers(resolvers, subscribers);

            if (directives != null)
            {
                builder.ApplyDirectives(directives);
            }

            var schema        = builder.Build();
            var introspection = Introspect.Schema(schema);

            return(new SchemaBuilder()
                   .Merge(schema, introspection)
                   .Build());
        }
Пример #2
0
        public static ISchema For(string typeDefinitions, Action <SchemaBuilder> configure = null)
        {
            var builder = new SchemaBuilder();

            configure?.Invoke(builder);
            return(builder.Build(typeDefinitions));
        }
Пример #3
0
    public async Task Part1_CreateSchema()
    {
        // 1. Create builder
        var builder = new SchemaBuilder();

        // 2. Create Query type from SDL by defining a type with 
        // name Query. This is by convention.
        builder.Add(@"
                type Query {
                    name: String
                }
                ");

        // 3. Build schema
        var schema = await builder.Build(new SchemaBuildOptions());

        // Assert that created schema matches the inputs
        // note: By convention the name on the Query root type is Query
        Assert.Equal("Query", schema.Query.Name);

        // Schema has methods for querying the fields of the type.
        // In this case assertion is done to check that "name" field exists
        // for Query type. Fields are key value pairs where key is the name
        // of the field and value is the actual field.
        Assert.Single(
            schema.GetFields(schema.Query.Name),
            fieldDef => fieldDef.Key == "name");
    }
Пример #4
0
    public async Task Parse_Sdl()
    {
        /* Given */
        var sdl =
            @"
                    """"""
                    tanka_import from ""Files/Import""
                    """"""

                    type Query {
                        imported: ImportedType
                    }
                 ";

        /* When */
        var builder = new SchemaBuilder()
                      // BuiltIn import providers are used
                      .Add(sdl);

        var schema = await builder.Build(new SchemaBuildOptions());

        /* Then */
        var importedType = schema.GetNamedType("ImportedType");

        Assert.NotNull(importedType);

        var importedField = schema.GetField(schema.Query.Name, "imported");

        Assert.Equal(importedType.Name, importedField.Type.Unwrap().Name);

        var nestedType = schema.GetNamedType("NestedObject");

        Assert.NotNull(nestedType);
    }
Пример #5
0
        public ISchema <TSchema> Build()
        {
            var builder = new SchemaBuilder <TSchema>(_entityTypeSelectorFactory);

            var graph = new DependencyGraph <Type>();

            foreach (var specification in _specifications)
            {
                foreach (var entityType in specification.Value.GetReferencedEntityTypes())
                {
                    graph.Add(specification.Key, entityType);
                }
            }

            var orderedSpecifications = graph.GetItemsInDependencyOrder()
                                        .Concat(_specifications.Keys)
                                        .Distinct()
                                        .Select(type => _specifications[type]);

            foreach (var specification in orderedSpecifications)
            {
                specification.Apply(builder);
            }

            return(builder.Build());
        }
Пример #6
0
        public async Task Create_Field_Subscriber()
        {
            /* Given */
            var builder = new SchemaBuilder();

            builder.Query(out var query)
            .Connections(connections =>
            {
                connections.Field(query, "field1", ScalarType.String,
                                  "test field",
                                  resolve => resolve.Run(context =>
                                                         ResolveSync.As(42)),
                                  subscribe => subscribe.Run((context, unsubscribe) =>
                                                             ResolveSync.Subscribe(new EventChannel <object>(), unsubscribe)));
            });


            /* When */
            var sut = builder.Build();

            /* Then */
            var result = await sut.GetSubscriber(query.Name, "field1")(null, CancellationToken.None);

            Assert.NotNull(result.Reader);
        }
        protected override async void OnClick()
        {
            var selectedLayer = MapView.Active.GetSelectedLayers().FirstOrDefault();

            if (selectedLayer == null || !(selectedLayer is FeatureLayer))
            {
                MessageBox.Show("You have to select a feature layer.  The selected layer's database connection is then used to create the new FeatureClass.");
                return;
            }
            var selectedFeatureLayer = selectedLayer as FeatureLayer;

            await QueuedTask.Run(() =>
            {
                var selectedLayerTable     = selectedFeatureLayer.GetTable();
                var stringFieldDescription = new ArcGIS.Core.Data.DDL.FieldDescription("TheString", FieldType.String);
                var intFieldDescription    = new ArcGIS.Core.Data.DDL.FieldDescription("TheInteger", FieldType.Integer);
                var dblFieldDescription    = new ArcGIS.Core.Data.DDL.FieldDescription("TheDouble", FieldType.Double)
                {
                    Precision = 9,
                    Scale     = 5
                };
                var dateFieldDescription = new ArcGIS.Core.Data.DDL.FieldDescription("TheDate", FieldType.Date);

                using (var geoDb = selectedLayerTable.GetDatastore() as Geodatabase)
                {
                    var fcName = selectedLayerTable.GetName();
                    try
                    {
                        FeatureClassDefinition originalFeatureClassDefinition   = geoDb.GetDefinition <FeatureClassDefinition>(fcName);
                        FeatureClassDescription originalFeatureClassDescription = new FeatureClassDescription(originalFeatureClassDefinition);

                        // Assemble a list of all of new field descriptions
                        var fieldDescriptions = new List <ArcGIS.Core.Data.DDL.FieldDescription>()
                        {
                            stringFieldDescription,
                            intFieldDescription,
                            dblFieldDescription,
                            dateFieldDescription
                        };
                        // Create a FeatureClassDescription object to describe the feature class to create
                        var fcDescription =
                            new FeatureClassDescription(fcName, fieldDescriptions, originalFeatureClassDescription.ShapeDescription);

                        // Create a SchemaBuilder object
                        SchemaBuilder schemaBuilder = new SchemaBuilder(geoDb);

                        // Add the modification to the feature class to our list of DDL tasks
                        schemaBuilder.Modify(fcDescription);

                        // Execute the DDL
                        bool success = schemaBuilder.Build();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show($@"Exception: {ex}");
                    }
                }
            });
        }
Пример #8
0
        public void Define()
        {
            /* Given */
            /* When */
            _builder.InputObject("ExampleInputObject", out var input)
            .Connections(connect => connect
                         .InputField(input, "a", ScalarType.Boolean));

            var schema = _builder.Build();

            /* Then */
            var inputFields = schema.GetInputFields(input.Name);

            Assert.Single(inputFields,
                          fk => fk.Key == "a" &&
                          (ScalarType)fk.Value.Type == ScalarType.Boolean);
        }
Пример #9
0
        public ReteGraph GetSchema()
        {
            var builder = new SchemaBuilder();
            var visitor = new SchemaReteVisitor();

            Visit(builder, visitor);
            return(builder.Build());
        }
Пример #10
0
        public static ISchema MergeSchemas(
            ISchema left,
            ISchema right)
        {
            var builder = new SchemaBuilder(left);

            Schema(builder, right);
            return(builder.Build());
        }
Пример #11
0
        public Schema Schema()
        {
            SchemaBuilder schemaBuilder = new SchemaBuilder(SafeType <Connector> .Get(this));
            ICollection <ConnectorAttributeInfo> connectorAttributeInfos = new List <ConnectorAttributeInfo>();

            connectorAttributeInfos.Add(ConnectorAttributeInfoBuilder.Build("User Logon Name"));
            schemaBuilder.DefineObjectClass(ObjectClass.ACCOUNT_NAME, connectorAttributeInfos);
            return(schemaBuilder.Build());
        }
Пример #12
0
        public void Should_AbleToSetDefinitionWithBuilder()
        {
            string name   = "name";
            var    schema = new SchemaBuilder <int>();

            var swaggerRoot = GetBasicSwaggerRootBuilder().Definition(name, schema).Build();

            Assert.Equal(schema.Build(), swaggerRoot.Definitions[name]);
        }
Пример #13
0
        public AppSchemaInternal(IDependencyResolver resolver)
        {
            var builder = new SchemaBuilder();

            builder.DependencyResolver = resolver;
            builder.Types.Include <Query>();
            builder.Types.Include <Mutation>();
            _schema = builder.Build(typedefinitions);
        }
Пример #14
0
    public ExecutionPathFacts()
    {
        // schema
        var builder = new SchemaBuilder();

        builder.Add((TypeSystemDocument) @"
type Node {
    child: Node
    path: [String]
    value: String
    children: [Node]
}

type Query {
    root: Node
}

type Mutation {
    root: Node
}

");

        var resolvers = new ResolversMap
        {
            {
                "Query", new FieldResolversMap
                {
                    { "root", context => new ValueTask <IResolverResult>(Resolve.As(new { })) }
                }
            },
            {
                "Mutation", new FieldResolversMap
                {
                    { "root", context => new ValueTask <IResolverResult>(Resolve.As(new { })) }
                }
            },
            {
                "Node", new FieldResolversMap
                {
                    { "child", context => new ValueTask <IResolverResult>(Resolve.As(new { })) },
                    {
                        "children", context => new ValueTask <IResolverResult>(Resolve.As(new[]
                        {
                            new { id = 0 },
                            new { id = 1 }
                        }))
                    },
                    { "value", context => new ValueTask <IResolverResult>(Resolve.As("value")) },
                    { "path", context => new ValueTask <IResolverResult>(Resolve.As(context.Path.Segments)) }
                }
            }
        };

        _schema = builder.Build(resolvers).Result;
    }
Пример #15
0
        public ExecutionPathFacts()
        {
            // schema
            var builder = new SchemaBuilder();

            builder.Object("Node", out var node)
            .Connections(connect => connect
                         .Field(node, "child", node)
                         .Field(node, "path", new List(ScalarType.String))
                         .Field(node, "value", ScalarType.String)
                         .Field(node, "children", new List(node)));

            builder.Query(out var query)
            .Connections(connect => connect
                         .Field(query, "root", node));

            builder.Mutation(out var mutation)
            .Connections(connect => connect
                         .Field(mutation, "root", node));

            var schema = builder.Build();

            var resolvers = new ResolverMap
            {
                {
                    "Query", new FieldResolverMap
                    {
                        { "root", context => new ValueTask <IResolveResult>(Resolve.As(new { })) }
                    }
                },
                {
                    "Mutation", new FieldResolverMap
                    {
                        { "root", context => new ValueTask <IResolveResult>(Resolve.As(new { })) }
                    }
                },
                {
                    "Node", new FieldResolverMap
                    {
                        { "child", context => new ValueTask <IResolveResult>(Resolve.As(new { })) },
                        {
                            "children", context => new ValueTask <IResolveResult>(Resolve.As(new[]
                            {
                                new { id = 0 },
                                new { id = 1 }
                            }))
                        },
                        { "value", context => new ValueTask <IResolveResult>(Resolve.As("value")) },
                        { "path", context => new ValueTask <IResolveResult>(Resolve.As(context.Path.Segments)) }
                    }
                }
            };

            _schema = SchemaTools.MakeExecutableSchema(schema, resolvers);
        }
Пример #16
0
        protected Schema ExecuteSchema(String scriptName)
        {
            var scb       = new SchemaBuilder(SafeType <Connector> .Get(this));
            var arguments = new Dictionary <String, Object>
            {
                { SchemaBldr, scb }
            };

            ExecuteScript(GetScript(scriptName), CreateBinding(arguments, OperationType.SCHEMA, null, null, null, null));
            return(scb.Build());
        }
        private EntityExpressionConverter <TupleParent <T1, T2> > CreateParentConverter <T1, T2>(bool defineChildEntity)
        {
            var schemaBuilder = new SchemaBuilder();

            if (defineChildEntity)
            {
                schemaBuilder.Define <TestTuple <T1, T2> >(entity => entity.SetTableName("TestTable"));
            }
            schemaBuilder.Define <TupleParent <T1, T2> >(entity => entity.SetTableName("ParentTable"));
            return(new EntityExpressionConverter <TupleParent <T1, T2> >(schemaBuilder.Build()));
        }
Пример #18
0
        public void Requires_Query()
        {
            /* Given */
            var builder = new SchemaBuilder();

            /* When */
            var exception = Assert.Throws <ArgumentNullException>(
                () => builder.Build());

            /* Then */
            Assert.Equal("types", exception.ParamName);
        }
Пример #19
0
        public void CanBuildWithGlobalPropertyComparer()
        {
            var sut = new SchemaBuilder(NullServiceProvider.Instance,
                                        new EntityComparerProvider(StringComparer.OrdinalIgnoreCase));

            sut.Entity(x => x.Source(NullDataSource.Instance).Name("Test").AddProperty("Id", TypeSystem.Integer));

            var actual = sut.Build();

            Assert.True(actual.ContainsEntity("test"));
            Assert.True(actual["test"].Metadata.Properties.ContainsKey("id"));
        }
Пример #20
0
    public static Task <ISchema> InitializeSchema()
    {
        var events  = new SingleValueEventChannel();
        var builder = new SchemaBuilder()
                      .Add(
            @"
                    type Query {
                        simple: String
                    }

                    type Mutation {
                        simple: String
                    }

                    type Subscription {
                        simple: String
                    }

                    schema {
                        query: Query
                        mutation: Mutation
                        subscription: Subscription
                    }
                    ");

        var resolvers = new ResolversMap
        {
            {
                "Query", new FieldResolversMap
                {
                    { "simple", context => new ValueTask <IResolverResult>(Resolve.As("value")) }
                }
            },
            {
                "Mutation", new FieldResolversMap
                {
                    { "simple", context => new ValueTask <IResolverResult>(Resolve.As("value")) }
                }
            },
            {
                "Subscription", new FieldResolversMap
                {
                    {
                        "simple",
                        (context, unsubscribe) => ResolveSync.Subscribe(events, unsubscribe),
                        context => new ValueTask <IResolverResult>(Resolve.As(context.ObjectValue))
                    }
                }
            }
        };

        return(builder.Build(resolvers, resolvers));
    }
Пример #21
0
        public void Requires_Query()
        {
            /* Given */
            var builder = new SchemaBuilder();

            /* When */
            var exception = Assert.Throws <ValidationException>(
                () => builder.Build());

            /* Then */
            Assert.Contains(exception.Result.Errors, error => error.Code == "SCHEMA_QUERY_ROOT_MISSING");
        }
Пример #22
0
        private const long DefaultMaxHeapSize = 150 * 1024 * 1024; // 150 MB

        public IndexTests()
        {
            using (var builder = new SchemaBuilder())
            {
                builder.AddBytesField("field1");
                field2 = builder.AddFacetField(nameof(field2));
                schema = builder.Build();
            }

            var path = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());

            indexDirectory = Directory.CreateDirectory(path);
        }
Пример #23
0
        public void Create_Query()
        {
            /* Given */
            var builder = new SchemaBuilder();

            builder.Query(out var query);

            /* When */
            var sut = builder.Build();

            /* Then */
            Assert.Equal(query, sut.Query);
        }
        public virtual StructContext StructFromIdl(Struct @struct)
        {
            var name          = _typeMangler.MangleTypeName(@struct.Name);
            var type          = _typeRegistry.FindType(_defaultNamespace, name);
            var schemaText    = _schemaBuilder.Build(type);
            var structContext = new StructContext(@struct.DocStringLines, name, type.CodeNamespace, type.Name,
                                                  @struct.IsServiceResponse, schemaText, 0);

            foreach (var field in @struct.Fields)
            {
                structContext.AddField(FieldFromIdl(field));
            }
            return(structContext);
        }
Пример #25
0
        public virtual Schema Schema()
        {
            if (null == _schema)
            {
                var builder = new SchemaBuilder(SafeType <Connector> .Get(this));
                // Account
                var accountInfoBuilder = new ObjectClassInfoBuilder();
                accountInfoBuilder.AddAttributeInfo(Name.INFO);
                accountInfoBuilder.AddAttributeInfo(OperationalAttributeInfos.PASSWORD);
                accountInfoBuilder.AddAttributeInfo(PredefinedAttributeInfos.GROUPS);
                accountInfoBuilder.AddAttributeInfo(ConnectorAttributeInfoBuilder.Build("firstName"));
                accountInfoBuilder.AddAttributeInfo(
                    ConnectorAttributeInfoBuilder.Define("lastName").SetRequired(true).Build());
                builder.DefineObjectClass(accountInfoBuilder.Build());

                // Group
                var groupInfoBuilder = new ObjectClassInfoBuilder();
                groupInfoBuilder.ObjectType = ObjectClass.GROUP_NAME;
                groupInfoBuilder.AddAttributeInfo(Name.INFO);
                groupInfoBuilder.AddAttributeInfo(PredefinedAttributeInfos.DESCRIPTION);
                groupInfoBuilder.AddAttributeInfo(
                    ConnectorAttributeInfoBuilder.Define("members")
                    .SetCreatable(false)
                    .SetUpdateable(false)
                    .SetMultiValued(true)
                    .Build());

                // Only the CRUD operations
                builder.DefineObjectClass(groupInfoBuilder.Build(), SafeType <SPIOperation> .Get <CreateOp>(),
                                          SafeType <SPIOperation> .ForRawType(typeof(SearchOp <>)), SafeType <SPIOperation> .Get <UpdateOp>(),
                                          SafeType <SPIOperation> .Get <DeleteOp>());

                // Operation Options
                builder.DefineOperationOption(OperationOptionInfoBuilder.BuildAttributesToGet(),
                                              SafeType <SPIOperation> .ForRawType(typeof(SearchOp <>)));

                // Support paged Search
                builder.DefineOperationOption(OperationOptionInfoBuilder.BuildPageSize(),
                                              SafeType <SPIOperation> .ForRawType(typeof(SearchOp <>)));
                builder.DefineOperationOption(OperationOptionInfoBuilder.BuildPagedResultsCookie(),
                                              SafeType <SPIOperation> .ForRawType(typeof(SearchOp <>)));

                // Support to execute operation with provided credentials
                builder.DefineOperationOption(OperationOptionInfoBuilder.BuildRunAsUser());
                builder.DefineOperationOption(OperationOptionInfoBuilder.BuildRunWithPassword());

                _schema = builder.Build();
            }
            return(_schema);
        }
Пример #26
0
        public void Create_Mutation()
        {
            /* Given */
            var builder = new SchemaBuilder();

            builder.Query(out _);
            builder.Mutation(out var mutation);

            /* When */
            var sut = builder.Build();

            /* Then */
            Assert.Equal(mutation, sut.Mutation);
        }
Пример #27
0
        public void T1()
        {
            var setter = A.Fake <Action <string> >();

            var schema = new SchemaBuilder(new Fb2Reader(_testLogger,
                                                         new XElement("A",
                                                                      new XElement("B", "value")).CreateReader()))

                         .AddRead("A")
                         .AddRead("B", setter);

            new SchemaRunner().Run(schema.Build());

            A.CallTo(() => setter("value")).MustHaveHappened();
        }
Пример #28
0
        public void Build()
        {
            /* Given */
            var builder = new SchemaBuilder()
                          // query is required to build schema
                          .Query(out _);

            /* When */
            var schema = builder.Build();

            /* Then */
            Assert.IsAssignableFrom <ISchema>(schema);
            Assert.IsType <SchemaGraph>(schema);
            Assert.NotNull(schema.Query);
        }
Пример #29
0
        public void BuildWorks()
        {
            using (var builder = new SchemaBuilder())
                using (var options = new TextOptions())
                {
                    uint field1 = builder.AddFacetField(nameof(field1));
                    uint field2 = builder.AddTextField("test2", options);
                    Assert.NotEqual(field1, field2);

                    var schema = builder.Build();
                    Assert.NotNull(schema);
                    Assert.Equal(nameof(field1), schema.GetFieldName(field1));

                    Assert.Throws <ObjectDisposedException>(() => builder.AddFacetField("test3"));
                }
        }
        public Schema Schema()
        {
            SchemaBuilder builder = new SchemaBuilder(SafeType <Connector> .Get <TstConnector>());

            for (int i = 0; i < 2; i++)
            {
                ObjectClassInfoBuilder classBuilder = new ObjectClassInfoBuilder();
                classBuilder.ObjectType = ("class" + i);
                for (int j = 0; j < 200; j++)
                {
                    classBuilder.AddAttributeInfo(ConnectorAttributeInfoBuilder.Build("attributename" + j, typeof(String)));
                }
                builder.DefineObjectClass(classBuilder.Build());
            }
            return(builder.Build());
        }