Creating schema with slash-graphql-cli

I have schema.txt with the following contents:

type Contact {
	c_email
	c_name
}

<c_email>: string .
<c_name>: string @index(trigram) .

I’m trying to use GitHub - dgraph-io/slash-graphql-cli: Command Line Tools for Slash GraphQL to create schema in my Slash instance:

slash-graphql update-schema -e https://bla.us-west-2.aws.cloud.dgraph.io/graphql -t API_KEY schema.txt

But it’s giving me error:

Error: resolving updateGQLSchema failed because input:3: Expected :, found Name

The same file has always been working for me with my localhost instance:

curl -X POST localhost:8080/alter --data-binary '@schema.txt'

How do I create schema using my schema.txt?

This is for pushing a GraphQL schema. That CLI does not appear to have a method for DQL schema. I believe you will have to use the alter endpoint with curl or similar.

That’s a bummer. I’m one of the early adopters that use DQL (and promote Dgraph!). Now that Dgraph have Slash (which is good), they seem to neglect DQL in favor of GraphQL.

Hey there,

that’s not true. I’m still a big pusher of DQL. I think I have made my opinions public more than once - DQL is significantly better than graphql. We’re not neglecting DQL in favour of GraphQL. The CLI app is a bit of a mismanagement on our end - we’re trying to remedy that. Perhaps a CLI for managing your cluster (@joaquin has a few prototypes on those)… or somethingg like that.

1 Like

Dgraph Cloud supports both GraphQL and DQL, but your schema mode needs to be set to flexible mode, which is not the default. This may not remedy slash-graphql, as mentioned with “bit of mismanagement on our end”, where its fate is yet to be determined.

In scope of tooling, most of my activities are toward deploying Dgraph on Docker or Kubernetes, and curl commands w/ DQL or GraphQL to interact with this. I am curious to try this out in the cloud now…

be right back

…back…

@wiradikusuma @chewxy @amaster507 When your mode is set to flexible:

DQL works well to the endpoint.

As an example, adapted from the Getting Started Guide:

export DGRAPH_ALPHA_ADDRESS="https://<RANDOM-NAME>.<REGION>.aws.cloud.dgraph.io"
export DGRAPH_CLOUD_API_KEY='<REDACTED>'

######
# Upload Dataset in RDF
###########
curl --silent "$DGRAPH_ALPHA_ADDRESS/mutate?commitNow=true" --request POST \
  --header "Content-Type: application/rdf"  \
  --header "x-auth-token: $DGRAPH_CLOUD_API_KEY" \
  --data $'
{
  set {
   _:luke <name> "Luke Skywalker" .
   _:luke <dgraph.type> "Person" .
   _:leia <name> "Princess Leia" .
   _:leia <dgraph.type> "Person" .
   _:han <name> "Han Solo" .
   _:han <dgraph.type> "Person" .
   _:lucas <name> "George Lucas" .
   _:lucas <dgraph.type> "Person" .
   _:irvin <name> "Irvin Kernshner" .
   _:irvin <dgraph.type> "Person" .
   _:richard <name> "Richard Marquand" .
   _:richard <dgraph.type> "Person" .

   _:sw1 <name> "Star Wars: Episode IV - A New Hope" .
   _:sw1 <release_date> "1977-05-25" .
   _:sw1 <revenue> "775000000" .
   _:sw1 <running_time> "121" .
   _:sw1 <starring> _:luke .
   _:sw1 <starring> _:leia .
   _:sw1 <starring> _:han .
   _:sw1 <director> _:lucas .
   _:sw1 <dgraph.type> "Film" .

   _:sw2 <name> "Star Wars: Episode V - The Empire Strikes Back" .
   _:sw2 <release_date> "1980-05-21" .
   _:sw2 <revenue> "534000000" .
   _:sw2 <running_time> "124" .
   _:sw2 <starring> _:luke .
   _:sw2 <starring> _:leia .
   _:sw2 <starring> _:han .
   _:sw2 <director> _:irvin .
   _:sw2 <dgraph.type> "Film" .

   _:sw3 <name> "Star Wars: Episode VI - Return of the Jedi" .
   _:sw3 <release_date> "1983-05-25" .
   _:sw3 <revenue> "572000000" .
   _:sw3 <running_time> "131" .
   _:sw3 <starring> _:luke .
   _:sw3 <starring> _:leia .
   _:sw3 <starring> _:han .
   _:sw3 <director> _:richard .
   _:sw3 <dgraph.type> "Film" .

   _:st1 <name> "Star Trek: The Motion Picture" .
   _:st1 <release_date> "1979-12-07" .
   _:st1 <revenue> "139000000" .
   _:st1 <running_time> "132" .
   _:st1 <dgraph.type> "Film" .
  }
}
' | jq

######
# Alter Schema
###########
curl --silent "$DGRAPH_ALPHA_ADDRESS/alter" --request POST \
  --header "x-auth-token: $DGRAPH_CLOUD_API_KEY" \
  --data $'
name: string @index(term) .
release_date: datetime @index(year) .
revenue: float .
running_time: int .
starring: [uid] .
director: [uid] .

type Person {
  name
}

type Film {
  name
  release_date
  revenue
  running_time
  starring
  director
}
' | jq

######
# Run Query
###########
curl --silent "$DGRAPH_ALPHA_ADDRESS/query" --request POST \
 --header "Content-Type: application/dql" \
 --header "x-auth-token: $DGRAPH_CLOUD_API_KEY" \
 --data $'
{
 me(func: has(starring)) {
   name
  }
}
' | jq

######
# Dump Schema
###########
curl --silent "$DGRAPH_ALPHA_ADDRESS/query" --request POST \
 --header "Content-Type: application/dql" \
 --header "x-auth-token: $DGRAPH_CLOUD_API_KEY" \
 --data $'schema {}' | jq

######
# Get all movies released after “1980”
###########
curl --silent "$DGRAPH_ALPHA_ADDRESS/query"  --request POST \
  --header "Content-Type: application/dql" \
  --header "x-auth-token: $DGRAPH_CLOUD_API_KEY" \
  --data $'
{
  me(func: allofterms(name, "Star Wars"), orderasc: release_date) @filter(ge(release_date, "1980")) {
    name
    release_date
    revenue
    running_time
    director {
     name
    }
    starring (orderasc: name) {
     name
    }
  }
}
' | jq

I hope this helps, let me know if any further questions.