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

Serialize function #20

Closed
wants to merge 16 commits into from
Closed
Show file tree
Hide file tree
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
13 changes: 8 additions & 5 deletions .github/workflows/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ jobs:
- name: setup
run: |
npm install -g esy@latest cross-env
# OCaml 4.06 and BuckleScript 6

# BuckleScript 6.x, OCaml 4.06
- name: install-build
run: |
esy install && esy b
Expand All @@ -32,13 +33,15 @@ jobs:
esy b dune runtest -f
- name: test-bsb6
run: |
cd tests_bucklescript && node ./run.js bsb6
# OCaml 4.02 and BuckleScript 5
cd tests_bucklescript && node run bsb6 && node run bsb6-serialize

# BuckleScript 5.x, OCaml 4.02
- name: install-build @402
run: |
esy @402 install && esy @402 b
- name: test-bsb5
run: |
cd tests_bucklescript && node ./run.js bsb5
cd tests_bucklescript && node run bsb5 && node run bsb5-serialize

env:
CI: true
CI: true
11 changes: 7 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ jobs:
- name: setup
run: |
npm install -g esy@latest cross-env
# OCaml 4.06 and BuckleScript 6

# BuckleScript 6.x, OCaml 4.06
- name: install-build
run: |
esy install && esy b
Expand All @@ -32,19 +33,21 @@ jobs:
esy b dune runtest -f
- name: test-bsb6
run: |
cd tests_bucklescript && node ./run.js bsb6
cd tests_bucklescript && node run bsb6 && node run bsb6-serialize
- name: Upload artifacts ${{ matrix.os }}
uses: actions/upload-artifact@master
with:
name: ${{ matrix.os }}-bsb6
path: _build/default/src/bucklescript_bin/bin.exe
# OCaml 4.02 and BuckleScript 5

# BuckleScript 5.x, OCaml 4.02
- name: install-build @402
run: |
esy @402 install && esy @402 b
- name: test-bsb5
run: |
cd tests_bucklescript && node ./run.js bsb5
cd tests_bucklescript && node run bsb5 && node run bsb5-serialize

- name: Upload artifacts ${{ matrix.os }}
uses: actions/upload-artifact@master
with:
Expand Down
93 changes: 60 additions & 33 deletions graphql_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,22 @@
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "enum",
"description": null,
"args": [],
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "ENUM",
"name": "SampleField",
"ofType": null
}
},
"isDeprecated": false,
"deprecationReason": null
}
],
"inputFields": null,
Expand Down Expand Up @@ -554,6 +570,35 @@
"enumValues": null,
"possibleTypes": null
},
{
"kind": "ENUM",
"name": "SampleField",
"description": null,
"fields": null,
"inputFields": null,
"interfaces": null,
"enumValues": [
{
"name": "FIRST",
"description": null,
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "SECOND",
"description": null,
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "THIRD",
"description": null,
"isDeprecated": false,
"deprecationReason": null
}
],
"possibleTypes": null
},
{
"kind": "OBJECT",
"name": "Lists",
Expand Down Expand Up @@ -943,35 +988,6 @@
"enumValues": null,
"possibleTypes": null
},
{
"kind": "ENUM",
"name": "SampleField",
"description": null,
"fields": null,
"inputFields": null,
"interfaces": null,
"enumValues": [
{
"name": "FIRST",
"description": null,
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "SECOND",
"description": null,
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "THIRD",
"description": null,
"isDeprecated": false,
"deprecationReason": null
}
],
"possibleTypes": null
},
{
"kind": "INPUT_OBJECT",
"name": "NonrecursiveInput",
Expand Down Expand Up @@ -2456,7 +2472,11 @@
{
"name": "skip",
"description": "Directs the executor to skip this field or fragment when the `if` argument is true.",
"locations": ["FIELD", "FRAGMENT_SPREAD", "INLINE_FRAGMENT"],
"locations": [
"FIELD",
"FRAGMENT_SPREAD",
"INLINE_FRAGMENT"
],
"args": [
{
"name": "if",
Expand All @@ -2477,7 +2497,11 @@
{
"name": "include",
"description": "Directs the executor to include this field or fragment only when the `if` argument is true.",
"locations": ["FIELD", "FRAGMENT_SPREAD", "INLINE_FRAGMENT"],
"locations": [
"FIELD",
"FRAGMENT_SPREAD",
"INLINE_FRAGMENT"
],
"args": [
{
"name": "if",
Expand All @@ -2498,7 +2522,10 @@
{
"name": "deprecated",
"description": "Marks an element of a GraphQL schema as no longer supported.",
"locations": ["FIELD_DEFINITION", "ENUM_VALUE"],
"locations": [
"FIELD_DEFINITION",
"ENUM_VALUE"
],
"args": [
{
"name": "reason",
Expand All @@ -2515,4 +2542,4 @@
]
}
}
}
}
1 change: 1 addition & 0 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ type VariousScalars {
boolean: Boolean!
nullableID: ID
id: ID!
enum: SampleField!
}

type Lists {
Expand Down
File renamed without changes.
4 changes: 4 additions & 0 deletions src/base/ppx_config.re
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ type config = {
verbose_logging: bool,
output_mode,
verbose_error_handling: bool,
serialization_experimental: bool,
apollo_mode: bool,
root_directory: string,
schema_file: string,
Expand All @@ -23,6 +24,9 @@ let output_mode = () => (config_ref^ |> Option.unsafe_unwrap).output_mode;

let apollo_mode = () => (config_ref^ |> Option.unsafe_unwrap).apollo_mode;

let serialization_experimental = () =>
(config_ref^ |> Option.unsafe_unwrap).serialization_experimental;

let verbose_error_handling = () =>
(config_ref^ |> Option.unsafe_unwrap).verbose_error_handling;

Expand Down
37 changes: 23 additions & 14 deletions src/base/result_decoder.re
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,17 @@ and unify_interface =
let (base_selection_set, fragments) =
List.fold_left(unwrap_type_conds, ([], []), selection_set.item);

let generate_case = (selection, ty, name) => (
name,
Res_object(
config.map_loc(span),
name,
List.map(unify_selection(error_marker, config, ty), selection),
),
);
let generate_case = (selection, ty, name) => {
poly_variant_name: name,
typename: name,
res_structure:
Res_object(
config.map_loc(span),
name,
List.map(unify_selection(error_marker, config, ty), selection),
),
};

let generate_fragment_case =
({item: {if_type_condition, if_selection_set, _}, _}) =>
switch (if_type_condition) {
Expand Down Expand Up @@ -227,7 +230,7 @@ and unify_union = (error_marker, config, span, union_meta, selection_set) =>
};

let is_record = has_directive("bsRecord", if_directives);
let result_decoder =
let res_structure =
unify_selection_set(
error_marker,
is_record,
Expand All @@ -236,7 +239,12 @@ and unify_union = (error_marker, config, span, union_meta, selection_set) =>
type_cond_ty,
Some(if_selection_set),
);
(if_type_condition.item, result_decoder);

{
poly_variant_name: if_type_condition.item,
typename: if_type_condition.item,
res_structure,
};
| None => assert(false)
};

Expand Down Expand Up @@ -323,17 +331,18 @@ and unify_variant = (error_marker, config, span, ty, selection_set) =>
)
| Ntr_nullable(i) => i
};
(
key,

let res_structure =
unify_type(
error_marker,
false,
config,
span,
inner_type,
item.fd_selection_set,
),
);
);

{poly_variant_name: key, typename: key, res_structure};
}
| FragmentSpread({span, _}) =>
raise_error(
Expand Down
11 changes: 8 additions & 3 deletions src/base/result_structure.re
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ type loc = Source_pos.ast_location;
type field_result =
| Fr_named_field(string, loc, t)
| Fr_fragment_spread(string, loc, string)
and typename_set = {
res_structure: t,
poly_variant_name: string,
typename: string,
}
and t =
| Res_nullable(loc, t)
| Res_array(loc, t)
Expand All @@ -20,9 +25,9 @@ and t =
| Res_custom_decoder(loc, string, t)
| Res_record(loc, string, list(field_result))
| Res_object(loc, string, list(field_result))
| Res_poly_variant_selection_set(loc, string, list((string, t)))
| Res_poly_variant_union(loc, string, list((string, t)), exhaustive_flag)
| Res_poly_variant_interface(loc, string, (string, t), list((string, t)))
| Res_poly_variant_selection_set(loc, string, list(typename_set))
| Res_poly_variant_union(loc, string, list(typename_set), exhaustive_flag)
| Res_poly_variant_interface(loc, string, typename_set, list(typename_set))
| Res_solo_fragment_spread(loc, string)
| Res_error(loc, string);

Expand Down
12 changes: 10 additions & 2 deletions src/bucklescript/graphql_ppx.re
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,10 @@ let rewrite_query = (loc, delim, query) => {
),
)
| Result.Ok(tokens) =>
let parser = Graphql_parser.make(tokens);
switch (Graphql_parser_document.parse_document(parser)) {
let result =
tokens |> Graphql_parser.make |> Graphql_parser_document.parse_document;

switch (result) {
| Result.Error(e) =>
raise(
Location.Error(
Expand Down Expand Up @@ -141,6 +143,12 @@ let mapper = (_config, _cookies) => {
| _ => true
| exception Not_found => true
},
serialization_experimental:
switch (Sys.getenv("GRAPHQL_PPX_SERIALIZATION_EXPERIMENTAL")) {
| "true" => true
| _ => false
| exception Not_found => false
},
apollo_mode:
switch (Sys.getenv("GRAPHQL_PPX_APOLLO_MODE")) {
| "true" => true
Expand Down
Loading