Mutation to add object inserts null values -- with pydgraph

Hey there,

I’m new to both dgraph and graphql, and experiencing a small issue which has been driving me nuts: a mutation to add an object succeeds, but inserts null value.

I can add/query data with no problems using GraphQL Playground, but performing the same operations programmatically from pydgraph gives me these problems.

My code is extremely simple, and I’d really appreciate some pointers. I’m sure I’m doing something simple wrong.

Schema:

type User {
  id: ID!
  name: String!
}

Python code:

client_stub = pydgraph.DgraphClientStub('localhost:9080')
client = pydgraph.DgraphClient(client_stub)

user = {
  'dgraph.type': 'User',
  'name': 'Mary',
}

txn = client.txn(read_only=False)
try:
  txn.mutate(set_obj=user)
  txn.commit()
except Exception as e:
  if isinstance(e, pydgraph.AbortedError):
    print(e)
  else:
    raise e
finally:
  txn.discard()

Versions

  • Python 3.7.2
  • Dgraph v20.03.1

Hi Shane. This is Derek from Dgraph. We’d be happy to help you get going with Dgraph. Would you like to have a quick call to discuss this issue you’re seeing? Please let me know.

Hi Derek, sure – I’m happy to do that. How do we make it happen?

I’ll send over an invite right now for tomorrow afternoon. Would that work for you?

Yep sounds good, thanks!

Also please remove my email from your reply if possible :wink:

1 Like

Hi Shane,

It was nice talking to you today. Please note that GraphQL Playground is GraphQL. pydgraph is GraphQL±. The predicate names are different in each. e.g., for a GraphQL schema like

type User {
id: ID!
name: String
}

The underlying predicate in Dgraph is User.name . So the pydgraph mutation isn’t writing to the right predicate to view it in GraphQL. Best thing to do is just use GraphQL queries and mutations. If you want to do it in Python, use a GraphQL library, not pydgraph.

Hope this helps,
Best,

Thanks Omar! I knew it would be something simple :slight_smile:

I appreciate the help.