porsche
(porscheme)
January 12, 2022, 5:25pm
1
I’m new to dgraph. I’m getting below when trying add a mution.
What am I doing wrong
{
"name": "t",
"url": "https://blue-surf-560034.us-east-1.aws.cloud.dgraph.io/mutate?commitNow=true",
"errors": [
{
"message": "while lexing _:x codeId 1234 . at line 1 column 3: Invalid input: c at lexText",
"extensions": {
"code": "ErrorInvalidRequest"
}
}
]
}
My type is below
type PersonDetail
{
codeId: Int! @id
timestamp: Int!
ethnicity: Int!
raceId: [Int]!
maritalStatusId: Int!
}
Tring to add mutation using RDF format
{
set {
_:x codeId 1234 .
_:x ethnicity 3.
_:x maritalStatusId 1 .
_:x timestamp 4567898223 .
_:x <dgraph.type> "PersonDetail" .
}
}
MichelDiz
(Michel Diz)
January 12, 2022, 5:45pm
2
This should be like this
{
set {
_:x <PersonDetail.codeId> "1234" .
_:x <PersonDetail.ethnicity> "3" .
_:x <PersonDetail.maritalStatusId> "1" .
_:x <PersonDetail.timestamp> "4567898223" .
_:x <dgraph.type> "PersonDetail" .
}
}
1 Like
amaster507
(Anthony Master)
January 12, 2022, 5:58pm
3
If you are using GraphQL and DQL together, you also need to correctly map your predicates.
Edit: @MichelDiz maps them correctly above.
This is not clear in any of the beginner docs. Let me know if you need direction on this further.
porsche
(porscheme)
January 12, 2022, 6:05pm
4
Why am I using double quotes around “1234” (int data type)?
Infact doc are very confusing…
For example in this link https://dgraph.io/docs/mutations/blank-nodes/
{
set {
_:class <student> _:x .
_:class <student> _:y .
_:class <name> "awesome class" .
_:class <dgraph.type> "Class" .
_:x <name> "Alice" .
_:x <dgraph.type> "Person" .
_:x <dgraph.type> "Student" .
_:x <planet> "Mars" .
_:x <friend> _:y .
_:y <name> "Bob" .
_:y <dgraph.type> "Person" .
_:y <dgraph.type> "Student" .
}
}
What does it mean by these two statements?
_:y <dgraph.type> "Person" .
_:y <dgraph.type> "Student" .
MichelDiz
(Michel Diz)
January 12, 2022, 6:25pm
5
Thats part of RDF spec.
Dgraph has Types(nodes, entities) that need to be explicitly pointed in your data. All entities you have should have this predicate.
porsche
(porscheme)
January 12, 2022, 7:16pm
6
Thanks for the replay @MichelDiz and @amaster507 .
What’s wrong with my query? sorry newbie quetions.
query {
queryPersonDetail() {
PersonDetail.timestamp
PersonDetail.codeId (filter: Tcode.codeConceptId: eq: "1234")
}
}
I’m getting below error when querying{
"name": "t",
"url": "https://blue-surf-560034.us-east-1.aws.cloud.dgraph.io/query?timeout=20s&debug=true",
"errors": [
{
"message": "line 4 column 1: Only aggregation/math functions allowed inside empty blocks. Got: persondetail.timestamp",
"extensions": {
"code": "ErrorInvalidRequest"
}
}
]
}
I changed my schema like belowtype Tcode
{
codeConceptId: Int! @id
}
type PersonDetail
{
id: ID!
codeId: Tcode!
timestamp: Int!
ethnicity: Tcode!
raceIds: [Tcode]!
maritalStatusId: Tcode!
}
Added mutation using RDF format like below{
set {
_:c <Tcode.codeConceptId> "1234" .
_:e <Tcode.codeConceptId> "3" .
_:m <Tcode.codeConceptId> "1" .
_:x <PersonDetail.codeId> _:c .
_:x <PersonDetail.ethnicity> _:e .
_:x <PersonDetail.maritalStatusId> _:m .
_:x <PersonDetail.timestamp> "4567898223" .
}
}
MichelDiz
(Michel Diz)
January 12, 2022, 7:23pm
7
You seem to be skipping a lot of steps in your studies. Take it easy.
The kind of “prefix” we have in RDF and DQL is just for DQL/Dgraph context. In GraphQL you can use the normal naming.
e.g:
query {
queryPersonDetail() {
timestamp
codeId (filter: {
codeConceptId: {
eq: "GraphQL"
}
})
}
You are mixing DQL syntax with GraphQL. If you are studying GraphQL, ignore DQL’s syntax and docs.
porsche
(porscheme)
January 12, 2022, 7:41pm
8
@MichelDiz thanks for the reply. Sorry for newbie question again.
I used your sample still get the same error.
query {
queryPersonDetail() {
timestamp
codeId (filter: {
codeConceptId: {
eq: "1234"
}
})
}
}
Then, I modified like below and new error.
query {
queryPersonDetail() {
timestamp
codeId (filter: codeConceptId: eq: "1234")
}
}
The above query erroring out…
{
"name": "t",
"url": "https://blue-surf-560034.us-east-1.aws.cloud.dgraph.io/query?timeout=20s&debug=true",
"errors": [
{
"message": "line 4 column 2: Only aggregation/math functions allowed inside empty blocks. Got: timestamp",
"extensions": {
"code": "ErrorInvalidRequest"
}
}
]
}
MichelDiz
(Michel Diz)
January 12, 2022, 7:52pm
9
I just gave you an example of syntax. You should check your schema and check the Dgraph’s GraphQL docs.
Also, you can use some GraphQL IDE to get the GraphQL Schema. For example GraphiQL GitHub - graphql/graphiql: GraphiQL & the GraphQL LSP Reference Ecosystem for building browser & IDE tools.
It shows the Schema and following the documented schema in the right panel or by using the autocomplete. You can build a valid query. Is that easy.
GraphQL can be confusing for newcomers. So I would recommend that you study GraphQL vanilla first and then go back to Dgraph’s GraphQL. Most of the functions that Dgraph uses are customized on top of GraphQL Spec. But it’s critical to learn the basics of GraphQL first.
1 Like
porsche
(porscheme)
January 13, 2022, 10:44pm
10
Thanks for your reply. I’m having issues with delete.
Using Ratel I executed below two mutation command variants…both succeeded in Ratel. But the node wasn’t deleted. Any idea what’s happening?
{
delete {
<0x7aec3d502> * * .
}
}
{
delete {
<0x7aec3d502> <Tcode.udi> * .
}
}
MichelDiz
(Michel Diz)
January 14, 2022, 12:32am
11
If you are talking about that the uid 0x7aec3d502
still there, but with no data/predicates in it. It is pretty normal. That’s how Dgraph is designed. The creation (leasing) of UIDs is a continued range. It is not possible to delete an already created number(UID). You can reuse them tho - for other purpose(but not really necessary). If you don’t understand this, just ignore it. Understand that Node has indeed been deleted. Do not worry about it.
Now, if you are saying that the data still there. Is that your data wasn’t added with the predicate “dgraph.type”. It have to have that predicate with the according Entity Type.
e.g:
{
set {
<0x7aec3d502> <Person.name> "Bob" .
<0x7aec3d502> <age> "22" .
<0x7aec3d502> <dgraph.type> "Person" .
}
}
If the dataset doesn’t have the type Person, and also the Type Schema doesn’t have the corresponding predicates. It won’t delete enything.
Cheers.
porsche
(porscheme)
January 14, 2022, 1:20am
12
Thanks for details explanation and I verified it too.
Interesting enough, I noticed something weird…
By accident I executed below mutation two times in Cloud Ratel. To my surprise, it created two nodes?
{
set {
_:x <Tcode.codeConceptId> "1234" .
_:x <Tcode.domain> "Generic domain" .
_:x <dgraph.type> "Tcode" .
}
}
So, I wanted switch to upsert block. Tried to follow instructions from this link https://dgraph.io/docs/mutations/external-ids-upsert-block . But, they are too hard to comprehend for newbie like me. Can some help me here, below is my type definition.
type Tcode
{
codeConceptId: Int! @id
domain: String!
}
MichelDiz
(Michel Diz)
January 14, 2022, 1:32am
13
porsche:
it created two nodes?
You are using a Blank Node (_:x
). Everytime you send a mutation with a Blank Node it will create a new node. No matter what.
A way to avoid this is using Upsert Block Mutation. Or use UID instead of Blank Node.
You have to pick the “source of truth” to use as a param. In your case I will pick codeConceptId.
In the mutation panel run this
upsert {
query {
var(func: eq(Tcode.codeConceptId, "1234")) {
ConceptId as uid
}
}
mutation {
set {
uid(ConceptId) <Tcode.codeConceptId> "1234" .
uid(ConceptId) <Tcode.domain> "Generic domain" .
uid(ConceptId) <dgraph.type> "Tcode" .
}
}
}