To facilitate better answering of questions, if you have a question, please fill in the following info. Otherwise, please delete the template.
What I want to do
I want to define a schema.graphql file in my repository and use that to set the schema in the cloud database programmatically through a script without using the dashboard.
Please list the high level idea of what you want to do
What I did
I tried to do that with the following code:
import { DgraphClient, clientStubFromCloudEndpoint, Operation } from "dgraph-js";
import fs from 'fs'
import path from 'path';
import dotenv from 'dotenv';
dotenv.config();
0
const dbURl = process.env.DATABASE_URL || "http://localhost:8080";
const apiKey = process.env.DGRAPH_CLOUD_API_KEY;
const clientStub = clientStubFromCloudEndpoint(dbURl, apiKey)
const dgraphClient = new DgraphClient(clientStub);
async function updateSchema() {
const schemaPath = path.join(__dirname, '../schema/schema.graphql');
const schema = fs.readFileSync(schemaPath, 'utf8')
const op = new Operation();
op.setSchema(schema);
await dgraphClient.alter(op);
}
updateSchema()
and the following schema:
type Space {
id: ID!
name: String!
}
I get an error message.
Error: 2 UNKNOWN: line 2 column 10: Expected new line after field declaration. Got @
When I set the same schema in the dashboard, it works. What do I do wrong?