How to use default variable and what can be used as a default variable?

So, to understand my question let’s say we have datatype of stores.

#data types
type Store {
    store
    geolocation
    info
}

# Define Directives and index
store: string .
geolocation: geo .
info: [default] .

So I want to add additional info as in default. I want to know more about the default and what datatypes can be added as info in the mutation. and most importantly how to add an integer, booleans???

_:store <dgraph.type> "store" .
_:store <geolocation>  "{'type':'Point','coordinates':[0.000000,0.000000]}"^^<geo:geojson> .
_:store <store> "North Pole" .
_:store <info> "the northest place on earth"  .  #Works
_:store <info> "{'type':'Point','coordinates':[180.000000,180.000000]}"^^<geo:geojson> .

_:store <info> 1 . #does't work this way to add integers.
_:store <info> True . #not a proper way to add booleans

So my question is how to add integers booleans and others and what are the search functionalities for these?

In RDF everything is under quotes. So the right way to do it is.

_:store <info> "1"^^<xs:int> .
_:store <info> "True"^^<xs:bool> .

First let’s clarify if you are trying to use the DQL syntax or the GraphQL syntax. This was posted in the GraphQL category, but all examples above (schema and RDFs) is DQL syntax.

If you are new and don’t understand the differences between DQL and GraphQL you should start here:

After you hash that out, take a look at:

https://dgraph.io/docs/query-language/schema/#rdf-types


And here is some more context from the docs:

If a schema type isn’t specified before a mutation adds triples for a predicate, then the type is inferred from the first mutation. This type is either:

  • type uid, if the first mutation for the predicate has nodes for the subject and object, or
  • derived from the RDF type, if the object is a literal and an RDF type is present in the first mutation, or
  • default type, otherwise.

default string

2 Likes

@amaster507 thanks for the information.
By the way is there a limit to what can default type be? for example can I add json, matricies or more complex entities as a “additional info”. and does it support any types of filters or “language support” as for example in strings.

default type is a string that is all. JSON is a string, but get’s no special treatment in Dgraph. There is this:

But it is for the GraphQL syntax and is a feature request not yet implemented or even accepted. I would think that if a JSON blob type was added in the GraphQL syntax though there would have to be some abstraction or lower level support in DQL instead of just a string but not necessarily.


Support for filters on non-indexed predicates was added with Dgraph v1.2.0

So yes it supports string filters as default is the same as string, just implied instead of imperative. You should review this documentation though for the difference that adding indexes to predicates gives you:

https://dgraph.io/docs/query-language/functions/

I believe to have language support you have to add the @lang directive in the DQL schema. But you can modify the schema from default to make this the case after the initial ingestion of the data.

1 Like