DateTime Schema definition

Hi. I was trying to get a field set as dateTime with index(hour) (not through Ratel) but via the /admin/schema endpoint and…

These did not work:
creationTime: DateTime @index(hour)

creationTime: DateTime @index(hour) .

creationTime: dateTime .

creationTime: datetime @index(hour) .

This worked

creationTime: DateTime

Which leads to these questions:

While I do know that dateTime is not a part of official GraphQL spec but a custom scalar,

  1. How do I add an index to a field in /admin/schema endpoint itself? I saw an example of doing this in /alter endpoint here: Indexes | Search | Dgraph Tour
  2. Since Types are case sensitive in GraphQL, and I am not able to find any GraphQL specific examples here: https://dgraph.io/docs//query-language/schema/#datetime-indices and the case is completely different.
  3. I tried searching but was not able to find relevant docs related to the ‘.’ character at the end of datetime @index(hour) . Can you point me to the docs where I can find more details regarding it? Also wondering how to something like that in GraphQL.
  4. Can all operations/alterations related to the schema be done in /admin/schema endpoint? Why should there be a separate /alter endpoint?

Suggestion: In docs, while suggesting examples/code, it would be better to provide both RDF and GraphQL code for the sample maybe via a tabbed interface (I see that its mostly RDF now) which has to be translated into GraphQL queries/mutations/schema.

You read the wrong documentation. i.e. for DQL.

Checkout: https://dgraph.io/docs/graphql/schema/search/#datetime & https://dgraph.io/docs/graphql/schema/search/#int-float-and-datetime

Excerpt:

| argument                  | constructedFilters    |
|---------------------------|-----------------------|
| year, month, day, or hour | lt, le, eq, ge and gt |

As well as @search with no arguments, DateTime also allows specifying how the search index should be built: by year, month, day or hour. @search defaults to year, but once you understand your data and query patterns, you might want to changes that like @search(by: [day]).

2 Likes

So, as this is a GraphQL related question, you should use GraphQL tag and made it under Users/Graphql. If you use Dgraph, we gonna think that you are asking about DQL.

PS. I have edited the tag and move the topic.

This syntax is DQL, not GraphQL. So it would never work. This is the right docs for it https://dgraph.io/docs/graphql/schema/search/

e.g

type Post {
    ...
    creationTime: DateTime @search(by: [hour])
}

See https://dgraph.io/docs/graphql/schema/search/#datetime

If you are on the road to GraphQL you should stick to /admin/schema. The Alter endpoint is exclusive to DQL. And if you stick to GraphQL, Dgraph will handle the schema for you.

The Tour part was created to be DQL, it can be worked to be work with GraphQL, but there are several examples and tutorials in the GraphQL part. The Tour is meant to show you what Dgraph can do. I can work on an extra tour that teaches how to convert DQL to GraphQL. But that is a long story* to do.

2 Likes

Thanks @MichelDiz @abhijit-kar

My bad. I was under the impression that since DQL was inspired by GraphQL that we can use it interchangeably. My bad. Got it now.

One last question. Can’t I use GraphQL queries in Ratel to explore the graph (with the graph diagram you show in Ratel?) The same query which returns me the data in insomnia does not work in Ratel.

Does Ratel not support GraphQL? Thanks.

Ratel doesn’t support GraphQL.

However you can write DQL in GraphQL.

Checkout: https://dgraph.io/docs/graphql/custom/graphqlpm/

1 Like

In addition to Abhijit’s answer, for GraphQL you can use; Postman, Insomnia, GraphiQL, the prisma client for GraphQL and several others.

I think the support for GraphQL is in the Ratel’s roadmap, it was mentioned internally. So sure it is in the plans.

1 Like