Beispiel #1
0
        private async Task ErrorsResultInFailedQuery(IDgraphClient client)
        {
            // maformed
            var q1result = await client.SchemaQuery("schema(pred: [name, friends, dob, scores]) { type ");

            q1result.IsSuccess.Should().BeFalse();

            // not a schema query
            var q2result = await client.SchemaQuery("{ q(func: uid(0x1)) { not-schema-query } }");

            q2result.IsSuccess.Should().BeFalse();
        }
Beispiel #2
0
        private async Task SchemaQueryWithRestrictions(IDgraphClient client)
        {
            var schemaResult = await client.SchemaQuery("schema(pred: [name, friends, dob, scores]) { type }");

            AssertResultIsSuccess(schemaResult);
            this.Assent(schemaResult.Value.ToString(), AssentConfiguration);
        }
Beispiel #3
0
        private async Task InitialSchemaIsAsExpected(IDgraphClient client)
        {
            var schemaResult = await client.SchemaQuery();

            AssertResultIsSuccess(schemaResult);
            this.Assent(schemaResult.Value.ToString(), AssentConfiguration);
        }
Beispiel #4
0
        private async Task AlterSchemaAgainAsExpected(IDgraphClient client)
        {
            var alterSchemaResult = await client.AlterSchema(ReadEmbeddedFile("altered.schema"));

            AssertResultIsSuccess(alterSchemaResult);

            var schemaResult = await client.SchemaQuery();

            AssertResultIsSuccess(schemaResult);
            this.Assent(schemaResult.Value.ToString(), AssentConfiguration);
        }
Beispiel #5
0
        static async Task Main(string[] args)
        {
            using (IDgraphClient client = DgraphDotNet.Clients.NewDgraphClient()) {
                client.Connect("127.0.0.1:9080");

                await client.AlterSchema(
                    "Username: string @index(hash) .\n"
                    + "Password: password .");

                var schemaResult = await client.SchemaQuery();

                if (schemaResult.IsFailed)
                {
                    Console.WriteLine($"Something went wrong getting schema.");
                    return;
                }

                Console.WriteLine("Queried schema and got :");
                foreach (var predicate in schemaResult.Value.Schema)
                {
                    Console.WriteLine(predicate.ToString());
                }

                while (true)
                {
                    Console.WriteLine("Hi, please enter your new username");
                    var username = Console.ReadLine();

                    // use Upsert to test for a node and value, and create if
                    // not already in the graph as an atomic operation.
                    var result = await client.Upsert(
                        "Username",
                        GraphValue.BuildStringValue(username),
                        $"{{\"uid\": \"_:myBlank\", \"Username\": \"{username}\"}}",
                        "myBlank");

                    if (result.IsFailed)
                    {
                        Console.WriteLine("Something went wrong : " + result);
                        continue;
                    }

                    var(node, existed) = result.Value;

                    if (existed)
                    {
                        Console.WriteLine("This user already existed.  Try another username.");
                        continue;
                    }

                    Console.WriteLine("Hi, please enter a password for the new user");
                    var password = Console.ReadLine();

                    using (var txn = client.NewTransaction()) {
                        var mutation = txn.NewMutation();
                        var property = Clients.BuildProperty(node, "Password", GraphValue.BuildPasswordValue(password));
                        if (property.IsFailed)
                        {
                            // ... something went wrong
                            Console.Write("uhh");
                        }
                        else
                        {
                            mutation.AddProperty(property.Value);
                            var err = await mutation.Submit();

                            if (err.IsFailed)
                            {
                                // ... something went wrong
                                Console.Write(err);
                            }
                        }
                        await txn.Commit();
                    }
                }
            }
        }