1 /* MIT (BSD) license - see LICENSE file for details */
3 #define __GRAPHQL_H__ 1
7 #include <ccan/list/list.h>
8 #include <ccan/tal/tal.h>
11 #define GRAPHQL_SUCCESS 0
13 // The following structures constitute the AST returned by the parser.
15 struct graphql_directive {
16 struct graphql_directive *next;
17 struct graphql_token *name;
18 struct graphql_arguments *args;
21 struct graphql_directives {
22 struct graphql_directive *first;
25 struct graphql_named_type {
26 struct graphql_token *name;
30 struct graphql_named_type *named;
31 // struct graphql_list_type *list;
32 // struct graphql_non_null_type *non_null;
35 struct graphql_default_value {
36 struct graphql_value *val;
39 struct graphql_variable_definition {
40 struct graphql_variable_definition *next;
41 struct graphql_variable *var;
42 struct graphql_type *type;
43 struct graphql_default_value *default_val;
44 struct graphql_directives *directives;
47 struct graphql_variable_definitions {
48 struct graphql_variable_definition *first;
51 struct graphql_variable {
52 struct graphql_token *name;
55 struct graphql_object_field {
56 struct graphql_object_field *next;
57 struct graphql_token *name;
58 struct graphql_value *val;
61 struct graphql_object_value {
62 struct graphql_object_field *first;
65 struct graphql_list_value {
66 struct graphql_token *val;
69 struct graphql_enum_value {
70 struct graphql_token *val;
73 struct graphql_null_value {
74 struct graphql_token *val;
77 struct graphql_string_value {
78 struct graphql_token *val;
81 struct graphql_boolean_value {
82 struct graphql_token *val;
85 struct graphql_float_value {
86 struct graphql_token *val;
89 struct graphql_int_value {
90 struct graphql_token *val;
93 struct graphql_value {
94 struct graphql_variable *var;
95 struct graphql_int_value *int_val;
96 struct graphql_float_value *float_val;
97 struct graphql_boolean_value *bool_val;
98 struct graphql_string_value *str_val;
99 struct graphql_null_value *null_val;
100 struct graphql_enum_value *enum_val;
101 struct graphql_list_value *list_val;
102 struct graphql_object_value *obj_val;
105 struct graphql_inline_fragment {
106 struct graphql_type_condition *type_cond;
107 struct graphql_directives *directives;
108 struct graphql_selection_set *sel_set;
111 struct graphql_type_condition {
112 struct graphql_named_type *named_type;
115 struct graphql_fragment_name {
116 struct graphql_token *name;
119 struct graphql_fragment_definition {
120 struct graphql_fragment_name *name;
121 struct graphql_type_condition *type_cond;
122 struct graphql_directives *directives;
123 struct graphql_selection_set *sel_set;
126 struct graphql_fragment_spread {
127 struct graphql_fragment_name *name;
128 struct graphql_directives *directives;
131 struct graphql_alias {
132 struct graphql_token *name;
135 struct graphql_argument {
136 struct graphql_argument *next;
137 struct graphql_token *name;
138 struct graphql_value *val;
141 struct graphql_arguments {
142 struct graphql_argument *first;
145 struct graphql_field {
146 struct graphql_alias *alias;
147 struct graphql_token *name;
148 struct graphql_arguments *args;
149 struct graphql_directives *directives;
150 struct graphql_selection_set *sel_set;
153 struct graphql_selection {
154 struct graphql_selection *next;
155 struct graphql_field *field;
156 struct graphql_fragment_spread *frag_spread;
157 struct graphql_inline_fragment *inline_frag;
160 struct graphql_selection_set {
161 struct graphql_selection *first;
164 struct graphql_operation_type {
165 struct graphql_token *op_type;
168 struct graphql_operation_definition {
169 struct graphql_operation_type *op_type;
170 struct graphql_token *op_name;
171 struct graphql_variable_definitions *vars;
172 struct graphql_directives *directives;
173 struct graphql_selection_set *sel_set;
176 struct graphql_executable_definition {
177 struct graphql_executable_definition *next_def;
178 struct graphql_operation_definition *op_def;
179 struct graphql_fragment_definition *frag_def;
182 struct graphql_executable_document {
183 struct graphql_executable_definition *first_def;
186 struct graphql_definition {
187 struct graphql_definition *next_def;
188 struct graphql_executable_definition *executable_def;
189 struct graphql_type_system_definition_or_extension *type_system_def;
192 struct graphql_document {
193 struct graphql_definition *first_def;
197 struct graphql_token {
198 struct list_node list;
199 unsigned int token_type;
200 unsigned int token_specific;
202 unsigned int source_line;
203 unsigned int source_column;
204 unsigned int source_len;
209 * input - string to parse
210 * ctx - parent tal context or NULL
211 * tokens - a variable to receive the resulting token list
213 * GRAPHQL_SUCCESS or an error string.
215 const char *graphql_lex(const char *input, const tal_t *ctx, struct list_head **tokens);
219 * tokens - the list produced by the lexer
220 * doc - a variable to receive the resulting abstract syntax tree (AST)
222 * GRAPHQL_SUCCESS or an error string.
224 const char *graphql_parse(struct list_head *tokens, struct graphql_executable_document **doc);
226 /* The lexer and parser in one function, for convenience. */
227 const char *graphql_lexparse(const char *input, const tal_t *ctx, struct list_head **tokens, struct graphql_executable_document **doc);