Can't rewrite mutation update GQLSchema because input Unexpected

Following the tutorial from: https://graphql.dgraph.io/quick-start/

I start up Docker in Windows and create a schema.graphql file and then try to use curl to import the schema into Dgraph and I get the following error:

{“errors”:[{“message”:“couldn’t rewrite mutation update"Error”}}]}GQLSchema because input:1: Unexpected \u003cInvalid\u00>3e\n",“extensions”:{“code”:“Error”}}]}

I even went to the Twitch video posted on youtube with Michael Compton and Kurt Kemple where they built the ToDo app and followed it exactly and I get the error but they don’t.

Example schema.graphql file:

type User {
  username: String! @id
  todos: [Todo] @hasInverse(field: user)
}

type Todo {
  id: ID!
  description: String!
  completed: Boolean
  user: User!
}

I do not understand what the error is and what is Unexpected.

I went into the Dgraph UI and tried to bulk edit the schema directly using the above and I get the error:

Could not alter schema: line 2 column 20: Expected new line after field declaration. Got @

It seems that the @ directives are not being understood correctly. Can someone help me understand what I am missing here.

Hi amaster507 ,
what version of dgraph are you using ?

i guess this error gets triggered when there is some syntax error in schema.
Make sure you are using this command
curl -X POST localhost:8080/admin/schema -d '@schema.graphql'

You can try to drop the schema and data from dgraph UI, if possible.

Above schema is of graphql and dgraph UI is for graphql±, so it won’t be able to recognise the syntax of graphql.
You can use any of graphql client like graphql-playground/insomnia/postman etc. for that.

Hmm, ok. That command looks like what I was using.

So I guess I am not quite sure still the difference between versions. I will pick this back up in the morning with fresh eyes and brain and try again. Thank you. Is there somewhere that lays out the differences between getting started with dgraph with graphql vs. graphql±

Yeah! looks like there is something wrong with the GraphQL schema you are supplying.
Can you copy/paste the schema here?

I understand the error message is not very useful in this case, it doesn’t tell what is exactly wrong.

@amaster507 could you have accidently copied some unicode characters wherever you’ve copied the schema from?

Ok here are the exact steps I followed:

  1. docker run -it -p 8080:8080 dgraph/standalone:v20.03.1
  2. Copied this code and saved it to a file at src/schema.graphql:
type Product {
    productID: ID!
    name: String @search(by: [term])
    reviews: [Review] @hasInverse(field: about)
}

type Customer {
    username: String! @id @search(by: [hash, regexp])
    reviews: [Review] @hasInverse(field: by)
}

type Review {
    id: ID!
    about: Product!
    by: Customer!
    comment: String @search(by: [fulltext])
    rating: Int @search
}
  1. Tried to post schema through curl: curl -X POST localhost:8080/admin/schema --data-binary '@src/schema.graphql'
Invoke-WebRequest : A parameter cannot be found that matches parameter name 'X'. 
At line:1 char:6
+ curl -X POST localhost:8080/admin/schema --data-binary '@src/schema.g ...      
+      ~~
    + CategoryInfo          : InvalidArgument: (:) [Invoke-WebRequest], Paramete 
   rBindingException
    + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Comman  
   ds.InvokeWebRequestCommand
  1. With Insomnia I pointed at http://localhost:8080/admin and refreshed the schema then ran:
query {
  health {
    instance
    address
    status
    group
    version
    uptime
    lastEcho
    ongoing
    indexing
  }
}

And received:

{
  "data": {
    "health": [
      {
        "instance": "zero",
        "address": "localhost:5080",
        "status": "healthy",
        "group": "0",
        "version": "v20.03.1",
        "uptime": 429,
        "lastEcho": 1592311583,
        "ongoing": [],
        "indexing": []
      },
      {
        "instance": "alpha",
        "address": "localhost:7080",
        "status": "healthy",
        "group": "1",
        "version": "v20.03.1",
        "uptime": 432,
        "lastEcho": 1592311583,
        "ongoing": [
          "opRollup"
        ],
        "indexing": []
      }
    ]
  }
}

EDIT: I just tried to use a mutation to upload same schema (after removing line breaks) and it worked with the following mutation:

mutation {
  updateGQLSchema(
    input: {
      set: {
        schema: "type Product { productID: ID! name: String @search(by: [term]) reviews: [Review] @hasInverse(field: about) } type Customer { username: String! @id @search(by: [hash, regexp]) reviews: [Review] @hasInverse(field: by) } type Review { id: ID! about: Product! by: Customer! comment: String @search(by: [fulltext]) rating: Int @search }"
      }
    }
  ) {
    gqlSchema {
      id
      schema
      generatedSchema
    }
  }
}

Hi @amaster507
The error is coming from the fact that Invoke-WebRequest command got invoked since by default the alias curl points to that in powershell. You should remove it

Remove-item alias:curl

Then execute the command again and it will use curl(if that’s installed) now.
Note: Store it in your profile, otherwise you will need to remove it every time.

2 Likes

@vardhanapoorv Thank you so much! So I was seeing the problem when many other people were not because 1) I was on Windows, 2) using Powershell, and 3) have installed curl. That makes more sense. I created a profile and added this command to that so I do not have to do it every time.

1 Like