DQL query syntax

I have GraphQL schema that look like the following:

type CountryCard {
    id: String! @id
    country: Country!
    product: Product!
    status: String!
    state: String!
}
type Product {
        id: String! @id
        title: String!
        subtitle: String
        price: Int!
}

The following DQL (from the go client) query works:

{
	q(func: type(Product)) {
		uid
		Product.title
		Product.subtitle
		Product.body
		Product.category
		Product.idnumber
		Product.price
	}
}

but a similarly formatted one for CountryCard does NOT work:

{
	q(func: type(CountryCard)) {
		uid
		CountryCard.country
		CountryCard.status
		CountryCard.description
	}
}

Question 1: Why does the 2nd query not work?

Question 2: In most examples, only the field name is listed in the query, not the Predicate dot field Product.title, why is this the case?

It should, check your dataset.

Which examples?

Question 1:

I do get a list of { uid: <uid> } but no other fields are even listed, are there specific reasons why a dataset would only return uid and no other fields? If a field is not set, will it get returned or break something?

Question 2:

https://dgraph.io/docs/query-language/graphql-fundamentals/

shows the golang client submitting a query that looks like this:

{
  bladerunner(func: eq(name@en, "Blade Runner")) {
    uid
    name@en
    initial_release_date
    netflix_id
  }
}

which does not appear to include the Predicate

Here is some context for your information:

CountryCard.description is not defined in your GraphQL example above, if you request a field in DQL that does not exist for a node it will not return null values but instead have no response in the JSON.

CountryCard.country returns a type not a scalar. You have to then request fields for this type to see any response:

	q(func: type(CountryCard)) {
		uid
		CountryCard.country {
                    uid
                }
		CountryCard.status
		CountryCard.description
	}
}

I am going to assume that the CountryCard.status is also missing for your nodes hence not seeing anything in the response other than uids.

Again please refer to the article I linked above in this reply. I believe that will do better to answer the question. Bottom line it is all about schema mapping. GraphQL schemas get mapped into a DQL schema with type dotted syntax, but that is not required for DQL schemas. They can have a predicate with names not having the type dotted notation.

1 Like

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.