Source file graphql_intf.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
(* IO signature *)
module type IO = sig
  type +'a t

  val return : 'a -> 'a t

  val bind : 'a t -> ('a -> 'b t) -> 'b t

  module Stream : sig
    type 'a t

    type +'a io

    val map : 'a t -> ('a -> 'b io) -> 'b t

    val iter : 'a t -> ('a -> unit io) -> unit io

    val close : 'a t -> unit
  end
  with type 'a io := 'a t
end

(* Field_error signature *)
module type Field_error = sig
  type t

  val message_of_field_error : t -> string

  val extensions_of_field_error :
    t -> (string * Yojson.Basic.t) list option
end

(** GraphQL schema signature *)
module type Schema = sig
  module Io : IO

  module StringMap : sig
    include Map.S with type key = string

    (* Map.S with type key = String.t *)
    exception Missing_key of key

    val find_exn : key -> 'a t -> 'a

    val find : key -> 'a t -> 'a option
  end

  type field_error

  (** {3 Base types } *)

  type 'ctx schema

  type ('ctx, 'src) field

  type 'ctx subscription_field

  type ('ctx, 'src) typ

  type 'a enum_value

  (** {3 Constructors } *)

  val schema :
    ?mutation_name:string ->
    ?mutations:('ctx, unit) field list ->
    ?subscription_name:string ->
    ?subscriptions:'ctx subscription_field list ->
    ?query_name:string ->
    ('ctx, unit) field list ->
    'ctx schema

  type deprecated = NotDeprecated | Deprecated of string option

  val enum_value :
    ?doc:string ->
    ?deprecated:deprecated ->
    string ->
    value:'a ->
    'a enum_value

  val obj :
    ?doc:string ->
    string ->
    fields:('ctx, 'src) field list ->
    ('ctx, 'src option) typ

  module Arg : sig
    type _ arg

    type _ arg_typ

    type (_, _) arg_list =
      | [] : ('a, 'a) arg_list
      | ( :: ) : 'a arg * ('b, 'c) arg_list -> ('b, 'a -> 'c) arg_list

    val arg : ?doc:string -> string -> typ:'a arg_typ -> 'a arg

    val arg' :
      ?doc:string ->
      string ->
      typ:'a option arg_typ ->
      default:Graphql_parser.const_value ->
      'a arg

    type 'a fixpoint = {
      obj: 'src 't 'args.
          ?doc:string
          -> string
          -> fields:('a -> ('t, 'args) arg_list)
          -> coerce:'args
          -> 't option arg_typ
    }

    val fix : ('a fixpoint -> 'a) -> 'a

    val scalar :
      ?doc:string ->
      string ->
      coerce:(Graphql_parser.const_value -> ('a, string) result) ->
      'a option arg_typ

    val enum :
      ?doc:string -> string -> values:'a enum_value list -> 'a option arg_typ

    val obj :
      ?doc:string ->
      string ->
      fields:('a, 'b) arg_list ->
      coerce:'b ->
      'a option arg_typ

    (* Argument constructors *)
    val int : int option arg_typ

    val string : string option arg_typ

    val bool : bool option arg_typ

    val float : float option arg_typ

    val guid : string option arg_typ

    val list : 'a arg_typ -> 'a list option arg_typ

    val non_null : 'a option arg_typ -> 'a arg_typ
  end

  type variable_map = Graphql_parser.const_value StringMap.t

  type fragment_map = Graphql_parser.fragment StringMap.t

  type 'ctx resolve_info = {
    ctx : 'ctx;
    field : Graphql_parser.field;
    fragments : fragment_map;
    variables : variable_map;
  }

  val field :
    ?doc:string ->
    ?deprecated:deprecated ->
    string ->
    typ:('ctx, 'a) typ ->
    args:('a, 'b) Arg.arg_list ->
    resolve:('ctx resolve_info -> 'src -> 'b) ->
    ('ctx, 'src) field

  val io_field :
    ?doc:string ->
    ?deprecated:deprecated ->
    string ->
    typ:('ctx, 'a) typ ->
    args:(('a, field_error) result Io.t, 'b) Arg.arg_list ->
    resolve:('ctx resolve_info -> 'src -> 'b) ->
    ('ctx, 'src) field

  val subscription_field :
    ?doc:string ->
    ?deprecated:deprecated ->
    string ->
    typ:('ctx, 'out) typ ->
    args:(('out Io.Stream.t, field_error) result Io.t, 'args) Arg.arg_list ->
    resolve:('ctx resolve_info -> 'args) ->
    'ctx subscription_field

  val enum :
    ?doc:string -> string -> values:'a enum_value list -> ('ctx, 'a option) typ

  val scalar :
    ?doc:string ->
    string ->
    coerce:('a -> Yojson.Basic.t) ->
    ('ctx, 'a option) typ

  val list : ('ctx, 'src) typ -> ('ctx, 'src list option) typ

  val non_null : ('ctx, 'src option) typ -> ('ctx, 'src) typ

  type ('ctx, 'a) abstract_value

  type ('ctx, 'a) abstract_typ = ('ctx, ('ctx, 'a) abstract_value option) typ

  val union : ?doc:string -> string -> ('ctx, 'a) abstract_typ

  type abstract_field

  val abstract_field :
    ?doc:string ->
    ?deprecated:deprecated ->
    string ->
    typ:(_, 'a) typ ->
    args:('a, _) Arg.arg_list ->
    abstract_field

  val interface :
    ?doc:string ->
    string ->
    fields:(('ctx, 'a) abstract_typ -> abstract_field list) ->
    ('ctx, 'a) abstract_typ

  val add_type :
    ('ctx, 'a) abstract_typ ->
    ('ctx, 'src option) typ ->
    'src ->
    ('ctx, 'a) abstract_value

  type 'a fixpoint = {
    obj: 'ctx 'src 'typ 'b. ?doc:string -> string ->
      fields:('a -> ('ctx, 'src) field list) ->
      ('ctx, 'src option) typ;

    interface : 'ctx 'src. ?doc:string -> string ->
      fields:('a -> abstract_field list) ->
      ('ctx, 'src) abstract_typ
  }

  val fix : ('a fixpoint -> 'a) -> 'a

  (** {3 Built-in scalars} *)

  val int : ('ctx, int option) typ

  val string : ('ctx, string option) typ

  val guid : ('ctx, string option) typ

  val bool : ('ctx, bool option) typ

  val float : ('ctx, float option) typ

  type variables = (string * Graphql_parser.const_value) list

  type 'a response = ('a, Yojson.Basic.t) result

  val execute :
    'ctx schema ->
    'ctx ->
    ?variables:variables ->
    ?operation_name:string ->
    Graphql_parser.document ->
    [ `Response of Yojson.Basic.t
    | `Stream of Yojson.Basic.t response Io.Stream.t ]
    response
    Io.t
  (** [execute schema ctx variables doc] evaluates the [doc] against [schema]
      with the given context [ctx] and [variables]. *)
end