示例#1
0
        internal Transaction(DgraphClient client)
        {
            this.client = client;

            context         = new TxnContext();
            context.LinRead = client.GetLinRead();
        }
示例#2
0
        public void Setup()
        {
            var connectionFactory = Substitute.For <IGRPCConnectionFactory>();

            transactionFactory = Substitute.For <ITransactionFactory>();
            client             = new DgraphClient(connectionFactory, transactionFactory);
        }
示例#3
0
        public async Task <IDgraphClient> GetDgraphClient()
        {
            // FIXME: This is not what you'd want to do in a real app.  Normally, there
            // would be tls to the server.  TO ADD - tests of running over https, and
            // with a Dgraph tls client certificate, and in enterprise mode.
            AppContext.SetSwitch(
                "System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);
            var client = new DgraphClient(GrpcChannel.ForAddress("http://127.0.0.1:9080"));

            if (!printed)
            {
                var result = await client.CheckVersion();

                if (result.IsSuccess)
                {
                    Log.Information("Connected to Dgraph version {Version}", result.Value);
                }
                else
                {
                    Log.Information("Failed to get Dgraph version {Error}", result);
                }
                printed = true;
            }

            return(client);
        }
        static void Main(string[] args)
        {
            var client = new DgraphClient(Grpc.Net.Client.GrpcChannel.ForAddress(new Uri("http://127.0.0.1:8000")));

            using (var txn = client.NewTransaction())
            {
                var alice = new Person {
                    Name = "Alice"
                };
                var json = JsonConvert.SerializeObject(alice);

                var transactionResult = txn.Mutate(new RequestBuilder().WithMutations(new MutationBuilder {
                    SetJson = json
                })).Result;
            }
            var schema = "`name: string @index(exact) .";
            var result = client.Alter(new Operation {
                Schema = schema
            });
        }
示例#5
0
 /// <summary>
 /// Creates a new gRPC connection to a Dgraph server with the specified channel.
 /// </summary>
 /// <param name="channel">A configured gRPC channel.</param>
 public DgraphConnection(Channel channel)
 {
     _channel = channel ?? throw new ArgumentNullException(nameof(channel));
     _client  = new DgraphClient(channel);
 }
示例#6
0
 public ITransaction NewTransaction(DgraphClient client)
 {
     return(new Transaction(client));
 }