Skip to content

Commit 6e973d1

Browse files
Add JSON Mutation Support (#15)
* Add JSON Mutation Support * JSON stringify mutation Co-authored-by: Abhimanyu Singh Gaur <12651351+abhimanyusinghgaur@users.noreply.github.com> * Update src/dgraph.ts Co-authored-by: Abhimanyu Singh Gaur <12651351+abhimanyusinghgaur@users.noreply.github.com> * check for string instead of object Co-authored-by: Abhimanyu Singh Gaur <12651351+abhimanyusinghgaur@users.noreply.github.com>
1 parent 8bb34dd commit 6e973d1

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/dgraph.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@ async function dqlQuery(query: string, variables: Record<string, any> = {}): Pro
3232
return response.json();
3333
}
3434

35-
async function dqlMutate(mutate: string): Promise<GraphQLResponse> {
35+
async function dqlMutate(mutate: string | Object): Promise<GraphQLResponse> {
3636
const response = await fetch(`${process.env.DGRAPH_URL}/mutate?commitNow=true`, {
3737
method: "POST",
3838
headers: {
39-
"Content-Type": "application/rdf",
39+
"Content-Type": typeof mutate === 'string' ? "application/rdf" : "application/json",
4040
"X-Auth-Token": process.env.DGRAPH_TOKEN || ""
4141
},
42-
body: mutate
42+
body: typeof mutate === 'string' ? mutate : JSON.stringify(mutate)
4343
})
4444
if (response.status !== 200) {
4545
throw new Error("Failed to execute DQL Mutate")

0 commit comments

Comments
 (0)