Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add introspection fields during schema creation #183

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 38 additions & 28 deletions graphql/src/graphql_schema.ml
Original file line number Diff line number Diff line change
Expand Up @@ -514,30 +514,6 @@ module Make (Io : IO) (Field_error : Field_error) = struct
subscription : 'ctx subscription_obj option;
}

let schema ?(mutation_name = "mutation") ?mutations
?(subscription_name = "subscription") ?subscriptions
?(query_name = "query") fields =
{
query =
{
name = query_name;
doc = None;
abstracts = ref [];
fields = lazy fields;
};
mutation =
Option.map mutations ~f:(fun fields ->
{
name = mutation_name;
doc = None;
abstracts = ref [];
fields = lazy fields;
});
subscription =
Option.map subscriptions ~f:(fun fields ->
{ name = subscription_name; doc = None; fields });
}

(* Constructor functions *)
let obj ?doc name ~fields =
let rec o =
Expand Down Expand Up @@ -1428,8 +1404,7 @@ module Make (Io : IO) (Field_error : Field_error) = struct
];
}

let add_built_in_fields schema =
let types = types_of_schema schema in
let add_built_in_fields schema types =
let schema_field =
Field
{
Expand Down Expand Up @@ -1950,7 +1925,6 @@ module Make (Io : IO) (Field_error : Field_error) = struct
let open Io.Infix in
let execute' schema ctx doc =
Io.return (collect_and_validate_fragments doc) >>=? fun fragments ->
let schema' = Introspection.add_built_in_fields schema in
Io.return (select_operation ?operation_name doc) >>=? fun op ->
let default_variables =
List.fold_left
Expand All @@ -1966,7 +1940,43 @@ module Make (Io : IO) (Field_error : Field_error) = struct
default_variables variables
in
let execution_ctx = { fragments; ctx; variables } in
execute_operation schema' execution_ctx op
execute_operation schema execution_ctx op
in
execute' schema ctx doc >>| to_response

let 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 =
fun ?(mutation_name = "mutation") ?mutations
?(subscription_name = "subscription") ?subscriptions
?(query_name = "query") fields ->
let schema =
{
query =
{
name = query_name;
doc = None;
abstracts = ref [];
fields = lazy fields;
};
mutation =
Option.map mutations ~f:(fun fields ->
{
name = mutation_name;
doc = None;
abstracts = ref [];
fields = lazy fields;
});
subscription =
Option.map subscriptions ~f:(fun fields ->
{ name = subscription_name; doc = None; fields });
}
in
let types = Introspection.types_of_schema schema in
Introspection.add_built_in_fields schema types
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about leaving add_built_in_fields as is and simply call it from here?

end