MCPcopy Index your code
hub / github.com/dgraph-io/dgraph / CreateUser

Method CreateUser

dgraphapi/acl.go:30–61  ·  view source on GitHub ↗
(username, password string)

Source from the content-addressed store, hash-verified

28}
29
30func (hc *HTTPClient) CreateUser(username, password string) (string, error) {
31 const query = `mutation addUser($name: String!, $pass: String!) {
32 addUser(input: [{name: $name, password: $pass}]) {
33 user {
34 name
35 }
36 }
37 }`
38 params := GraphQLParams{
39 Query: query,
40 Variables: map[string]interface{}{
41 "name": username,
42 "pass": password,
43 },
44 }
45 resp, err := hc.RunGraphqlQuery(params, true)
46 if err != nil {
47 return "", err
48 }
49
50 var r struct {
51 AddUser struct {
52 User []struct {
53 Name string
54 }
55 }
56 }
57 if err := json.Unmarshal(resp, &r); err != nil {
58 return "", errors.Wrap(err, "error unmarshalling response")
59 }
60 return r.AddUser.User[0].Name, nil
61}
62
63func (hc *HTTPClient) GetCurrentUser() (string, error) {
64 const query = `query {

Callers 7

TestAclBasicMethod · 0.80
TestGetCurrentUserMethod · 0.80
resetUserFunction · 0.80
TestGuardianAccessMethod · 0.80

Calls 1

RunGraphqlQueryMethod · 0.95

Tested by 7

TestAclBasicMethod · 0.64
TestGetCurrentUserMethod · 0.64
resetUserFunction · 0.64
TestGuardianAccessMethod · 0.64