From 9136fef430ee0bac542a1f6aabeb35c6a957920f Mon Sep 17 00:00:00 2001 From: Damian Tarnawski Date: Wed, 27 Mar 2024 14:07:32 +0100 Subject: [PATCH] Add Operation_Kind to queries --- cli.odin | 7 ++++--- runtime.js | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/cli.odin b/cli.odin index ae98dea..589694d 100644 --- a/cli.odin +++ b/cli.odin @@ -252,8 +252,6 @@ write_query_data :: proc(b: ^strings.Builder, schema: gql.Schema, field: gql.Fie write(b, field.name) write(b, "(vars) {\n") write(b, "\treturn '") - write(b, operation_type) - write(b, "{") write(b, field.name) if len(field.args) > 0 { @@ -272,7 +270,7 @@ write_query_data :: proc(b: ^strings.Builder, schema: gql.Schema, field: gql.Fie write_type_fields(b, schema, field.value) - write(b, "}'\n}\n\n") + write(b, "'\n}\n\n") } { // query_data @@ -296,6 +294,9 @@ write_query_data :: proc(b: ^strings.Builder, schema: gql.Schema, field: gql.Fie write(b, "\tname : \"") write(b, field.name) write(b, "\",\n") + write(b, "\tkind : \"") + write(b, operation_type) + write(b, "\",\n") write(b, "\tget_body : query_get_body_") write(b, field.name) write(b, ",\n") diff --git a/runtime.js b/runtime.js index e1e1296..6fbf832 100644 --- a/runtime.js +++ b/runtime.js @@ -16,11 +16,19 @@ * @returns {string} */ +/** + * @enum {(typeof Operation_Kind)[keyof typeof Operation_Kind]} */ +export const Operation_Kind = /** @type {const} */({ + Query : "query", + Mutation: "mutation", +}) + /** * @template TVars * @template TValue * @typedef {object } Query_Data * @property {string } name + * @property {Operation_Kind } kind * @property {Query_Get_Body} get_body * @property {TValue } initial_value * @property {TVars } _type_vars @@ -68,6 +76,14 @@ export function request_init_init(request_init, query) { request_init.body = '{"query":'+JSON.stringify(query)+'}' } + +/** + * @param {string} query + * @returns {string} */ +export function query_to_requestinit_body(query) { + return '{"query":'+JSON.stringify(query)+'}' +} + /** * @param {string | URL | Request} url * @param {Request_Init } request_init