Skip to content

Commit

Permalink
Add Operation_Kind to queries
Browse files Browse the repository at this point in the history
  • Loading branch information
thetarnav committed Mar 27, 2024
1 parent 997c7f9 commit 9136fef
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
7 changes: 4 additions & 3 deletions cli.odin
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand All @@ -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")
Expand Down
16 changes: 16 additions & 0 deletions runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<TVars>} get_body
* @property {TValue } initial_value
* @property {TVars } _type_vars
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 9136fef

Please sign in to comment.