6 * graphql - Routines to lex and parse GraphQL.
8 * This code contains routines to lex and parse GraphQL code.
9 * This code was written per the spec at:
10 * https://spec.graphql.org/draft/
11 * ...dated Fri, May 21, 2021 at the time of writing.
12 * Copyright (c) 2021 WhiteCloudFarm.org <robert.lee.dickinson@gmail.com>
13 * <https://github.com/rl-d/ccan>
17 * #include "ccan/graphql/graphql.h"
19 * int main(int argc, char *argv[])
21 * const char *input_string = "{ fieldName }";
22 * struct list_head *output_tokens;
23 * struct graphql_executable_document *output_document;
25 * const char *errmsg = graphql_lexparse(
27 * NULL, // tal context
28 * &output_tokens, // variable to receive tokens
29 * &output_document); // variable to receive AST
32 * struct graphql_token *last_token;
33 * last_token = list_tail(output_tokens, struct graphql_token, list);
34 * printf("Line %d, col %d: %s",
35 * last_token->source_line,
36 * last_token->source_column + last_token->source_len,
39 * // Normally you would check every indirection in the resulting AST for null
40 * // pointers, but for simplicity of example:
41 * printf("A field from the parsed string: %s\n",
42 * output_document->first_def->op_def->sel_set->
43 * first->field->name->token_string);
46 * output_tokens = tal_free(output_tokens);
51 int main(int argc, char *argv[])
53 /* Expect exactly one argument */
57 if (strcmp(argv[1], "depends") == 0) {
58 printf("ccan/list\n");
59 printf("ccan/take\n");
61 printf("ccan/tal/str\n");
62 printf("ccan/utf8\n");