Simple example throws error: "Missing colon in type declaration."

Moved from GitHub dgraph-js/87

Posted by alexnitta:

When I follow the instructions in dgraph-js/examples/simple/README.md, I get this error when running node index.js:

ERROR:  { Error: 2 UNKNOWN: line 3 column 16: Missing colon in type declaration. Got

    at Object.exports.createStatusError (/Users/alexnitta/Downloads/dgraph-js/examples/simple/node_modules/grpc/src/common.js:91:15)
    at Object.onReceiveStatus (/Users/alexnitta/Downloads/dgraph-js/examples/simple/node_modules/grpc/src/client_interceptors.js:1209:28)
    at InterceptingListener._callNext (/Users/alexnitta/Downloads/dgraph-js/examples/simple/node_modules/grpc/src/client_interceptors.js:568:42)
    at InterceptingListener.onReceiveStatus (/Users/alexnitta/Downloads/dgraph-js/examples/simple/node_modules/grpc/src/client_interceptors.js:618:8)
    at callback (/Users/alexnitta/Downloads/dgraph-js/examples/simple/node_modules/grpc/src/client_interceptors.js:847:24)
  code: 2,
  metadata: Metadata { _internal_repr: {}, flags: 0 },
  details:
   'line 3 column 16: Missing colon in type declaration. Got \n' }

Looking at the schema in index.js starting on line 22, I noticed that there are no predicates defined under the Person or School types. They each have what looks like a reference to the predicates defined below, for example:

        type School {
            name // this seems to reference the `name` defined below
        }

        name: string @index(exact) .

However, I found that I can resolve this error by adding colons and scalar types within the Person and School type definitions. The full schema that runs without throwing errors is:

    const schema = `
        type Person {
            name: string
            age: int
            married: bool
            loc: geo
            dob: datetime
            friend: [uid]
            school: uid
        }

        type School {
            name: string
        }

        name: string @index(exact) .
        age: int .
        married: bool .
        loc: geo .
        dob: datetime .
        friend: [uid] @reverse .
    `;

My solution also mirrors what is shown in the docs here: https://docs.dgraph.io/query-language/#type-definition

Interestingly, when I use a similar pattern on my own project, it still doesn’t resolve the error. It feels like something changed recently about how the Types work in the JavaScript client that is perhaps buggy.

1 Like

paulftw commented :

Shorter form field declarations (without the explicit type) is what Dgraph will settle on eventually. For now users have to add colon and a type name.

@prashant-shahi we need to update examples to work with current stable release of Dgraph and keep support for future versions in a branch.

1 Like

alexnitta commented :

@paulftw That’s good to know, thank you.

Can you explain why this schema from my project is also throwing the same error?

    typeEmployee: string .
    firstName: string .
    lastName: string .
    gender: string .
    title: string .
    email: string @index(exact) @upsert .

    type Employee {
        typeEmployee: string
        firstName: string
        lastName: string
        gender: string
        title: string
        email: string
    }

At least I think it’s the same error; it has the same error code, although my log looks a bit different:

{ Error: 2 UNKNOWN: Missing colon
    at Object.exports.createStatusError (/api/node_modules/grpc/src/common.js:91:15)
    at Object.onReceiveStatus (/api/node_modules/grpc/src/client_interceptors.js:1204:28)
    at InterceptingListener._callNext (/api/node_modules/grpc/src/client_interceptors.js:568:42)
    at InterceptingListener.onReceiveStatus (/api/node_modules/grpc/src/client_interceptors.js:618:8)
    at callback (/api/node_modules/grpc/src/client_interceptors.js:845:24)
  code: 2,
  metadata: Metadata { _internal_repr: {}, flags: 0 },
  details: 'Missing colon' }

paulftw commented :

I’ve tried uploading your second schema to a local dgraph v1.1.0 instance and it worked fine.
I get an error only if I don’t add a newline character at the end of the type declaration.

My guess is you are either looking at an old error message or your code is somehow sending the old schema definition

alexnitta commented :

Thanks for trying that out from your end. I have it working now. I think that somehow the old schema definition was cached because of how my Docker volume is set up. I was able to resolve it by removing the container and its volume and starting without a volume.

I would not have expected this to make a difference, since I was using op.setDropAll(true); before doing op.setSchema(schema);.

prashant-shahi commented :

@paulftw Let’s only make the changes to the test cases as the CI test cases run on Dgraph master.

Changes to sample examples can wait till we make the Dgraph changes public. Maintaining a separate branch for every change would be more iterative.

prashant-shahi commented :

@alexnitta Thanks for raising this issue. We have reverted the type system changes from examples for now.

You could refer to the Type System Docs. Please be mindful of the Dgraph manual version on the left sidebar.