diff --git a/snapshot_tests/operations/errors/expected/fragmentWrongType.res.txt b/snapshot_tests/operations/errors/expected/fragmentWrongType.res.txt new file mode 100644 index 00000000..defb0000 --- /dev/null +++ b/snapshot_tests/operations/errors/expected/fragmentWrongType.res.txt @@ -0,0 +1,18 @@ + + We've found a bug for you! + snapshot_tests/operations/errors/fragmentWrongType.res:12:5-14:5 + + 10 │ %graphql(` + 11 │ query MyQuery @ppxConfig(templateTagImport: "gql", templateTagReturnT + │ ype: "bool") { + 12 │ lists { + 13 │  ...WrongFragmentName + 14 │  } + 15 │ } + 16 │ `) + 17 │ + + This has type: [> #WrongFragmentName] + But this function argument is expecting: [#ListFragment] + The second variant type does not allow tag(s) #WrongFragmentName + diff --git a/snapshot_tests/operations/errors/fragmentWrongType.res b/snapshot_tests/operations/errors/fragmentWrongType.res new file mode 100644 index 00000000..3df1b3bc --- /dev/null +++ b/snapshot_tests/operations/errors/fragmentWrongType.res @@ -0,0 +1,16 @@ +%graphql(` + fragment ListFragment on Lists { + nullableOfNullable + nullableOfNonNullable + } +`) + +module WrongFragmentName = ListFragment + +%graphql(` + query MyQuery @ppxConfig(templateTagImport: "gql", templateTagReturnType: "bool") { + lists { + ...WrongFragmentName + } + } +`) diff --git a/snapshot_tests/operations/expected/apollo/compile/fragmentDefinition.res.txt b/snapshot_tests/operations/expected/apollo/compile/fragmentDefinition.res.txt index c2260c9f..a757a991 100644 --- a/snapshot_tests/operations/expected/apollo/compile/fragmentDefinition.res.txt +++ b/snapshot_tests/operations/expected/apollo/compile/fragmentDefinition.res.txt @@ -278,7 +278,7 @@ var Wrapper = { var Raw$5 = {}; -var query$3 = "query MyQuery($arg1: String) {\nl1: lists {\n...ListFragment \n}\n\nl2: lists {\n__typename \n...ListFragment \n...ListFragment \n}\n\nl3: lists {\n__typename \nnullableOfNullable \n...ListFragment \n...ListFragment \n}\n\nl4: lists {\n__typename \nnullableOfNullable \n...InlineListFragment \n}\n\nl5: lists {\n...FragmentWithArgs \n}\n\n}\nfragment FragmentWithArgs on Lists {\n__typename \nlistWithArg(arg1: $arg1) \n}\nfragment InlineListFragment on Lists {\n__typename \nnullableOfNullable \nnullableOfNonNullable \n}\nfragment ListFragment on Lists {\n__typename \nnullableOfNullable \nnullableOfNonNullable \n}\n"; +var query$3 = "query MyQuery($arg1: String) {\nl1: lists {\n...ListFragment \n}\n\nl2: lists {\n__typename \n...ListFragment \n...ListFragment \n}\n\nl3: lists {\n__typename \nnullableOfNullable \n...ListFragment \n...ListFragment \n}\n\nl4: lists {\n__typename \nnullableOfNullable \n...InlineListFragment \n}\n\nl5: lists {\n...FragmentWithArgs \n}\n\n}\nfragment FragmentWithArgs on Lists {\n__typename \nlistWithArg(arg1: $arg1) \n}\nfragment ListFragment on Lists {\n__typename \nnullableOfNullable \nnullableOfNonNullable \n}\nfragment InlineListFragment on Lists {\n__typename \nnullableOfNullable \nnullableOfNonNullable \n}\n"; function parse$5(value) { var value$1 = value.l2; diff --git a/snapshot_tests/operations/expected/apollo/compile/tagged_template.res.txt b/snapshot_tests/operations/expected/apollo/compile/tagged_template.res.txt index a1ffc067..b21aacbe 100644 --- a/snapshot_tests/operations/expected/apollo/compile/tagged_template.res.txt +++ b/snapshot_tests/operations/expected/apollo/compile/tagged_template.res.txt @@ -1,6 +1,7 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; +var Gatsby = require("gatsby"); var ApolloClient = require("apollo-client"); function deepMerge(json1, param) { @@ -13,23 +14,23 @@ var Graphql_ppx_runtime = { var Raw = {}; -var query = (graphql` - query { - variousScalars { - __typename - nullableString - string - nullableInt - int - nullableFloat - float - nullableBoolean - boolean - nullableID - id - } - } -`); +var query = graphql`query { +variousScalars { +__typename +nullableString +string +nullableInt +int +nullableFloat +float +nullableBoolean +boolean +nullableID +id +} + +} +`; function parse(value) { var value$1 = value.variousScalars; @@ -117,23 +118,23 @@ var MyTypes = {}; var Raw$1 = {}; -var query$1 = (graphql` - query { - variousScalars { - __typename - nullableString - string - nullableInt - int - nullableFloat - float - nullableBoolean - boolean - nullableID - id - } - } -`); +var query$1 = graphql`query { +variousScalars { +__typename +nullableString +string +nullableInt +int +nullableFloat +float +nullableBoolean +boolean +nullableID +id +} + +} +`; function parse$1(value) { var value$1 = value.variousScalars; @@ -219,23 +220,23 @@ var MyQuery1a = { var Raw$2 = {}; -var query$2 = (graphql` - query { - variousScalars { - __typename - nullableString - string - nullableInt - int - nullableFloat - float - nullableBoolean - boolean - nullableID - id - } - } -`); +var query$2 = graphql`query { +variousScalars { +__typename +nullableString +string +nullableInt +int +nullableFloat +float +nullableBoolean +boolean +nullableID +id +} + +} +`; function parse$2(value) { var value$1 = value.variousScalars; @@ -321,23 +322,23 @@ var MyQuery1b = { var Raw$3 = {}; -var query$3 = (require("gatsby").graphql` - query { - variousScalars { - __typename - nullableString - string - nullableInt - int - nullableFloat - float - nullableBoolean - boolean - nullableID - id - } - } -`); +var query$3 = Gatsby.graphql`query { +variousScalars { +__typename +nullableString +string +nullableInt +int +nullableFloat +float +nullableBoolean +boolean +nullableID +id +} + +} +`; function parse$3(value) { var value$1 = value.variousScalars; @@ -423,23 +424,23 @@ var MyQuery2 = { var Raw$4 = {}; -var query$4 = (require("gatsby").graphql` - query { - variousScalars { - __typename - nullableString - string - nullableInt - int - nullableFloat - float - nullableBoolean - boolean - nullableID - id - } - } -`); +var query$4 = Gatsby.graphql`query { +variousScalars { +__typename +nullableString +string +nullableInt +int +nullableFloat +float +nullableBoolean +boolean +nullableID +id +} + +} +`; function parse$4(value) { var value$1 = value.variousScalars; @@ -525,23 +526,23 @@ var MyQuery3 = { var Raw$5 = {}; -var query$5 = (require("gatsby")` - query { - variousScalars { - __typename - nullableString - string - nullableInt - int - nullableFloat - float - nullableBoolean - boolean - nullableID - id - } - } -`); +var query$5 = Gatsby.graphql`query { +variousScalars { +__typename +nullableString +string +nullableInt +int +nullableFloat +float +nullableBoolean +boolean +nullableID +id +} + +} +`; function parse$5(value) { var value$1 = value.variousScalars; @@ -627,13 +628,12 @@ var MyQuery4 = { var Raw$6 = {}; -var query$6 = (require("gatsby")` - fragment ListFragment on Lists { - __typename - nullableOfNullable - nullableOfNonNullable - } -`); +var query$6 = Gatsby.graphql`fragment ListFragment on Lists { +__typename +nullableOfNullable +nullableOfNonNullable +} +`; function parse$6(value) { var value$1 = value.nullableOfNullable; @@ -692,13 +692,13 @@ var ListFragment = { var Raw$7 = {}; -var query$7 = (require("gatsby")` - query MyQuery5 { - lists { - ...ListFragment - } - } -`); +var query$7 = Gatsby.graphql`query MyQuery5 { +lists { +...ListFragment +} + +} +${query$6}`; function parse$7(value) { return { @@ -738,14 +738,13 @@ var MyQuery5 = { var Raw$8 = {}; -var query$8 = ((frag_0) => require("gatsby")` - query MyQuery6 { - lists { - ...ListFragment - } - } - ${frag_0} -`)(query$6); +var query$8 = Gatsby.graphql`query MyQuery6 { +lists { +...ListFragment +} + +} +${query$6}`; function parse$8(value) { return { @@ -785,13 +784,13 @@ var MyQuery6 = { var Raw$9 = {}; -var query$9 = (graphql` - query MyQuery7 { - lists { - ...ListFragment - } - } -`); +var query$9 = graphql`query MyQuery7 { +lists { +...ListFragment +} + +} +${query$6}`; function parse$9(value) { return { diff --git a/snapshot_tests/operations/expected/apollo/generate/fragmentDefinition.res.txt b/snapshot_tests/operations/expected/apollo/generate/fragmentDefinition.res.txt index fe2f324b..2f312234 100644 --- a/snapshot_tests/operations/expected/apollo/generate/fragmentDefinition.res.txt +++ b/snapshot_tests/operations/expected/apollo/generate/fragmentDefinition.res.txt @@ -522,9 +522,9 @@ l5: lists { ", FragmentWithArgs.query, ), - InlineListFragment.query, + ListFragment.query, ), - ListFragment.query, + InlineListFragment.query, ) let parse = (value): t => { l1: { diff --git a/snapshot_tests/operations/expected/apollo/generate/tagged_template.res.txt b/snapshot_tests/operations/expected/apollo/generate/tagged_template.res.txt index b30c035c..6c3dd713 100644 --- a/snapshot_tests/operations/expected/apollo/generate/tagged_template.res.txt +++ b/snapshot_tests/operations/expected/apollo/generate/tagged_template.res.txt @@ -2,6 +2,9 @@ module Graphql_ppx_runtime = { // mock let deepMerge = (json1, _) => json1 } + +@variadic @taggedTemplate +external graphql: (array, array) => string = "graphql" module MyQuery: { @@ocaml.warning("-32-30") module Raw: { @@ -78,23 +81,26 @@ function back to the original JSON compatible data ") } type rec t = {variousScalars: t_variousScalars} type rec t_variables = unit - let query = ( - %raw("graphql` - query { - variousScalars { - nullableString - string - nullableInt - int - nullableFloat - float - nullableBoolean - boolean - nullableID - id - } - } -`"): string + let query = graphql( + [ + "query { +variousScalars { +nullableString +string +nullableInt +int +nullableFloat +float +nullableBoolean +boolean +nullableID +id +} + +} +", + ], + [], ) let parse = (value): t => { variousScalars: { @@ -248,6 +254,9 @@ function back to the original JSON compatible data ") module MyTypes = { type query } + +@variadic @taggedTemplate +external graphql: (array, array) => MyTypes.query = "graphql" module MyQuery1a: { @@ocaml.warning("-32-30") module Raw: { @@ -324,23 +333,26 @@ function back to the original JSON compatible data ") } type rec t = {variousScalars: t_variousScalars} type rec t_variables = unit - let query = ( - %raw("graphql` - query { - variousScalars { - nullableString - string - nullableInt - int - nullableFloat - float - nullableBoolean - boolean - nullableID - id - } - } -`"): MyTypes.query + let query = graphql( + [ + "query { +variousScalars { +nullableString +string +nullableInt +int +nullableFloat +float +nullableBoolean +boolean +nullableID +id +} + +} +", + ], + [], ) let parse = (value): t => { variousScalars: { @@ -490,6 +502,9 @@ function back to the original JSON compatible data ") external toJson: Raw.t => Js.Json.t = "%identity" external variablesToJson: Raw.t_variables => Js.Json.t = "%identity" } + +@variadic @taggedTemplate +external graphql: (array, array) => string = "graphql" module MyQuery1b: { @@ocaml.warning("-32-30") module Raw: { @@ -566,23 +581,26 @@ function back to the original JSON compatible data ") } type rec t = {variousScalars: t_variousScalars} type rec t_variables = unit - let query = ( - %raw("graphql` - query { - variousScalars { - nullableString - string - nullableInt - int - nullableFloat - float - nullableBoolean - boolean - nullableID - id - } - } -`"): string + let query = graphql( + [ + "query { +variousScalars { +nullableString +string +nullableInt +int +nullableFloat +float +nullableBoolean +boolean +nullableID +id +} + +} +", + ], + [], ) let parse = (value): t => { variousScalars: { @@ -808,23 +826,29 @@ function back to the original JSON compatible data ") } type rec t = {variousScalars: t_variousScalars} type rec t_variables = unit - let query = ( - %raw("require("gatsby").graphql` - query { - variousScalars { - nullableString - string - nullableInt - int - nullableFloat - float - nullableBoolean - boolean - nullableID - id - } - } -`"): string + @module("gatsby") @taggedTemplate + external graphql: (array, array) => string = "graphql" + external graphql_allow_string: string => string = "%identity" + let query = graphql( + [ + "query { +variousScalars { +nullableString +string +nullableInt +int +nullableFloat +float +nullableBoolean +boolean +nullableID +id +} + +} +", + ], + [], ) let parse = (value): t => { variousScalars: { @@ -1050,23 +1074,29 @@ function back to the original JSON compatible data ") } type rec t = {variousScalars: t_variousScalars} type rec t_variables = unit - let query = ( - %raw("require("gatsby").graphql` - query { - variousScalars { - nullableString - string - nullableInt - int - nullableFloat - float - nullableBoolean - boolean - nullableID - id - } - } -`"): string + @module("gatsby") @taggedTemplate + external graphql: (array, array) => string = "graphql" + external graphql_allow_string: string => string = "%identity" + let query = graphql( + [ + "query { +variousScalars { +nullableString +string +nullableInt +int +nullableFloat +float +nullableBoolean +boolean +nullableID +id +} + +} +", + ], + [], ) let parse = (value): t => { variousScalars: { @@ -1292,23 +1322,29 @@ function back to the original JSON compatible data ") } type rec t = {variousScalars: t_variousScalars} type rec t_variables = unit - let query = ( - %raw("require("gatsby")` - query { - variousScalars { - nullableString - string - nullableInt - int - nullableFloat - float - nullableBoolean - boolean - nullableID - id - } - } -`"): string + @module("gatsby") @taggedTemplate + external graphql: (array, array) => string = "graphql" + external graphql_allow_string: string => string = "%identity" + let query = graphql( + [ + "query { +variousScalars { +nullableString +string +nullableInt +int +nullableFloat +float +nullableBoolean +boolean +nullableID +id +} + +} +", + ], + [], ) let parse = (value): t => { variousScalars: { @@ -1496,13 +1532,18 @@ function back to the original JSON-compatible data ") nullableOfNonNullable: option>, } type t_Lists = t - let query = ( - %raw("require("gatsby")` - fragment ListFragment on Lists { - nullableOfNullable - nullableOfNonNullable - } -`"): string + @module("gatsby") @taggedTemplate + external graphql: (array, array) => string = "graphql" + external graphql_allow_string: string => string = "%identity" + let query = graphql( + [ + "fragment ListFragment on Lists { +nullableOfNullable +nullableOfNonNullable +} +", + ], + [], ) let parse = ( (value): t => { @@ -1593,14 +1634,21 @@ function back to the original JSON compatible data ") } type rec t = {lists: ListFragment.t_Lists} type rec t_variables = unit - let query = ( - %raw("require("gatsby")` - query MyQuery5 { - lists { - ...ListFragment - } - } -`"): string + @module("gatsby") @taggedTemplate + external graphql: (array, array) => string = "graphql" + external graphql_allow_string: string => string = "%identity" + let query = graphql( + [ + "query MyQuery5 { +lists { +...ListFragment +} + +} +", + "", + ], + [ListFragment.query], ) let parse = (value): t => { lists: { @@ -1651,15 +1699,21 @@ function back to the original JSON compatible data ") } type rec t = {lists: ListFragment.t_Lists} type rec t_variables = unit - let query = ( - %raw("(frag_0) => require("gatsby")` - query MyQuery6 { - lists { - ...ListFragment - } - } - ${frag_0} -`")(ListFragment.query): string + @module("gatsby") @taggedTemplate + external graphql: (array, array) => string = "graphql" + external graphql_allow_string: string => string = "%identity" + let query = graphql( + [ + "query MyQuery6 { +lists { +...ListFragment +} + +} +", + "", + ], + [ListFragment.query], ) let parse = (value): t => { lists: { @@ -1710,14 +1764,18 @@ function back to the original JSON compatible data ") } type rec t = {lists: ListFragment.t_Lists} type rec t_variables = unit - let query = ( - %raw("graphql` - query MyQuery7 { - lists { - ...ListFragment - } - } -`"): string + let query = graphql( + [ + "query MyQuery7 { +lists { +...ListFragment +} + +} +", + "", + ], + [ListFragment.query], ) let parse = (value): t => { lists: { @@ -1778,14 +1836,17 @@ function back to the original JSON-compatible data ") nullableOfNonNullable: option>, } type t_Lists = t - @module("apollo-client") external graphql: array => int = "gql" - let query = graphql([ - "fragment ListFragment8 on Lists { + @module("apollo-client") @variadic external gql: (array, array) => int = "gql" + let query = gql( + [ + "fragment ListFragment8 on Lists { nullableOfNullable nullableOfNonNullable } ", - ]) + ], + [], + ) let parse = ( (value): t => { nullableOfNullable: { @@ -1932,8 +1993,8 @@ function back to the original JSON compatible data ") variousScalars: t_variousScalars, } type rec t_variables = unit - @module("apollo-client") external graphql: (array, int) => int = "gql" - let query = graphql( + @module("apollo-client") @variadic external gql: (array, array) => int = "gql" + let query = gql( [ "query MyQuery8 { lists { @@ -1957,7 +2018,7 @@ id ", "", ], - ListFragment8.query, + [ListFragment8.query], ) let parse = (value): t => { lists: { diff --git a/snapshot_tests/operations/expected/native/generate/fragmentDefinition.res.txt b/snapshot_tests/operations/expected/native/generate/fragmentDefinition.res.txt index fe2f324b..2f312234 100644 --- a/snapshot_tests/operations/expected/native/generate/fragmentDefinition.res.txt +++ b/snapshot_tests/operations/expected/native/generate/fragmentDefinition.res.txt @@ -522,9 +522,9 @@ l5: lists { ", FragmentWithArgs.query, ), - InlineListFragment.query, + ListFragment.query, ), - ListFragment.query, + InlineListFragment.query, ) let parse = (value): t => { l1: { diff --git a/snapshot_tests/operations/expected/native/generate/tagged_template.res.txt b/snapshot_tests/operations/expected/native/generate/tagged_template.res.txt index b30c035c..6c3dd713 100644 --- a/snapshot_tests/operations/expected/native/generate/tagged_template.res.txt +++ b/snapshot_tests/operations/expected/native/generate/tagged_template.res.txt @@ -2,6 +2,9 @@ module Graphql_ppx_runtime = { // mock let deepMerge = (json1, _) => json1 } + +@variadic @taggedTemplate +external graphql: (array, array) => string = "graphql" module MyQuery: { @@ocaml.warning("-32-30") module Raw: { @@ -78,23 +81,26 @@ function back to the original JSON compatible data ") } type rec t = {variousScalars: t_variousScalars} type rec t_variables = unit - let query = ( - %raw("graphql` - query { - variousScalars { - nullableString - string - nullableInt - int - nullableFloat - float - nullableBoolean - boolean - nullableID - id - } - } -`"): string + let query = graphql( + [ + "query { +variousScalars { +nullableString +string +nullableInt +int +nullableFloat +float +nullableBoolean +boolean +nullableID +id +} + +} +", + ], + [], ) let parse = (value): t => { variousScalars: { @@ -248,6 +254,9 @@ function back to the original JSON compatible data ") module MyTypes = { type query } + +@variadic @taggedTemplate +external graphql: (array, array) => MyTypes.query = "graphql" module MyQuery1a: { @@ocaml.warning("-32-30") module Raw: { @@ -324,23 +333,26 @@ function back to the original JSON compatible data ") } type rec t = {variousScalars: t_variousScalars} type rec t_variables = unit - let query = ( - %raw("graphql` - query { - variousScalars { - nullableString - string - nullableInt - int - nullableFloat - float - nullableBoolean - boolean - nullableID - id - } - } -`"): MyTypes.query + let query = graphql( + [ + "query { +variousScalars { +nullableString +string +nullableInt +int +nullableFloat +float +nullableBoolean +boolean +nullableID +id +} + +} +", + ], + [], ) let parse = (value): t => { variousScalars: { @@ -490,6 +502,9 @@ function back to the original JSON compatible data ") external toJson: Raw.t => Js.Json.t = "%identity" external variablesToJson: Raw.t_variables => Js.Json.t = "%identity" } + +@variadic @taggedTemplate +external graphql: (array, array) => string = "graphql" module MyQuery1b: { @@ocaml.warning("-32-30") module Raw: { @@ -566,23 +581,26 @@ function back to the original JSON compatible data ") } type rec t = {variousScalars: t_variousScalars} type rec t_variables = unit - let query = ( - %raw("graphql` - query { - variousScalars { - nullableString - string - nullableInt - int - nullableFloat - float - nullableBoolean - boolean - nullableID - id - } - } -`"): string + let query = graphql( + [ + "query { +variousScalars { +nullableString +string +nullableInt +int +nullableFloat +float +nullableBoolean +boolean +nullableID +id +} + +} +", + ], + [], ) let parse = (value): t => { variousScalars: { @@ -808,23 +826,29 @@ function back to the original JSON compatible data ") } type rec t = {variousScalars: t_variousScalars} type rec t_variables = unit - let query = ( - %raw("require("gatsby").graphql` - query { - variousScalars { - nullableString - string - nullableInt - int - nullableFloat - float - nullableBoolean - boolean - nullableID - id - } - } -`"): string + @module("gatsby") @taggedTemplate + external graphql: (array, array) => string = "graphql" + external graphql_allow_string: string => string = "%identity" + let query = graphql( + [ + "query { +variousScalars { +nullableString +string +nullableInt +int +nullableFloat +float +nullableBoolean +boolean +nullableID +id +} + +} +", + ], + [], ) let parse = (value): t => { variousScalars: { @@ -1050,23 +1074,29 @@ function back to the original JSON compatible data ") } type rec t = {variousScalars: t_variousScalars} type rec t_variables = unit - let query = ( - %raw("require("gatsby").graphql` - query { - variousScalars { - nullableString - string - nullableInt - int - nullableFloat - float - nullableBoolean - boolean - nullableID - id - } - } -`"): string + @module("gatsby") @taggedTemplate + external graphql: (array, array) => string = "graphql" + external graphql_allow_string: string => string = "%identity" + let query = graphql( + [ + "query { +variousScalars { +nullableString +string +nullableInt +int +nullableFloat +float +nullableBoolean +boolean +nullableID +id +} + +} +", + ], + [], ) let parse = (value): t => { variousScalars: { @@ -1292,23 +1322,29 @@ function back to the original JSON compatible data ") } type rec t = {variousScalars: t_variousScalars} type rec t_variables = unit - let query = ( - %raw("require("gatsby")` - query { - variousScalars { - nullableString - string - nullableInt - int - nullableFloat - float - nullableBoolean - boolean - nullableID - id - } - } -`"): string + @module("gatsby") @taggedTemplate + external graphql: (array, array) => string = "graphql" + external graphql_allow_string: string => string = "%identity" + let query = graphql( + [ + "query { +variousScalars { +nullableString +string +nullableInt +int +nullableFloat +float +nullableBoolean +boolean +nullableID +id +} + +} +", + ], + [], ) let parse = (value): t => { variousScalars: { @@ -1496,13 +1532,18 @@ function back to the original JSON-compatible data ") nullableOfNonNullable: option>, } type t_Lists = t - let query = ( - %raw("require("gatsby")` - fragment ListFragment on Lists { - nullableOfNullable - nullableOfNonNullable - } -`"): string + @module("gatsby") @taggedTemplate + external graphql: (array, array) => string = "graphql" + external graphql_allow_string: string => string = "%identity" + let query = graphql( + [ + "fragment ListFragment on Lists { +nullableOfNullable +nullableOfNonNullable +} +", + ], + [], ) let parse = ( (value): t => { @@ -1593,14 +1634,21 @@ function back to the original JSON compatible data ") } type rec t = {lists: ListFragment.t_Lists} type rec t_variables = unit - let query = ( - %raw("require("gatsby")` - query MyQuery5 { - lists { - ...ListFragment - } - } -`"): string + @module("gatsby") @taggedTemplate + external graphql: (array, array) => string = "graphql" + external graphql_allow_string: string => string = "%identity" + let query = graphql( + [ + "query MyQuery5 { +lists { +...ListFragment +} + +} +", + "", + ], + [ListFragment.query], ) let parse = (value): t => { lists: { @@ -1651,15 +1699,21 @@ function back to the original JSON compatible data ") } type rec t = {lists: ListFragment.t_Lists} type rec t_variables = unit - let query = ( - %raw("(frag_0) => require("gatsby")` - query MyQuery6 { - lists { - ...ListFragment - } - } - ${frag_0} -`")(ListFragment.query): string + @module("gatsby") @taggedTemplate + external graphql: (array, array) => string = "graphql" + external graphql_allow_string: string => string = "%identity" + let query = graphql( + [ + "query MyQuery6 { +lists { +...ListFragment +} + +} +", + "", + ], + [ListFragment.query], ) let parse = (value): t => { lists: { @@ -1710,14 +1764,18 @@ function back to the original JSON compatible data ") } type rec t = {lists: ListFragment.t_Lists} type rec t_variables = unit - let query = ( - %raw("graphql` - query MyQuery7 { - lists { - ...ListFragment - } - } -`"): string + let query = graphql( + [ + "query MyQuery7 { +lists { +...ListFragment +} + +} +", + "", + ], + [ListFragment.query], ) let parse = (value): t => { lists: { @@ -1778,14 +1836,17 @@ function back to the original JSON-compatible data ") nullableOfNonNullable: option>, } type t_Lists = t - @module("apollo-client") external graphql: array => int = "gql" - let query = graphql([ - "fragment ListFragment8 on Lists { + @module("apollo-client") @variadic external gql: (array, array) => int = "gql" + let query = gql( + [ + "fragment ListFragment8 on Lists { nullableOfNullable nullableOfNonNullable } ", - ]) + ], + [], + ) let parse = ( (value): t => { nullableOfNullable: { @@ -1932,8 +1993,8 @@ function back to the original JSON compatible data ") variousScalars: t_variousScalars, } type rec t_variables = unit - @module("apollo-client") external graphql: (array, int) => int = "gql" - let query = graphql( + @module("apollo-client") @variadic external gql: (array, array) => int = "gql" + let query = gql( [ "query MyQuery8 { lists { @@ -1957,7 +2018,7 @@ id ", "", ], - ListFragment8.query, + [ListFragment8.query], ) let parse = (value): t => { lists: { diff --git a/snapshot_tests/operations/expected/records/compile/fragmentDefinition.res.txt b/snapshot_tests/operations/expected/records/compile/fragmentDefinition.res.txt index 910a8f2b..ea1cbf49 100644 --- a/snapshot_tests/operations/expected/records/compile/fragmentDefinition.res.txt +++ b/snapshot_tests/operations/expected/records/compile/fragmentDefinition.res.txt @@ -263,7 +263,7 @@ var Wrapper = { var Raw$5 = {}; -var query$3 = "query MyQuery($arg1: String) {\nl1: lists {\n...ListFragment \n}\n\nl2: lists {\n...ListFragment \n...ListFragment \n}\n\nl3: lists {\nnullableOfNullable \n...ListFragment \n...ListFragment \n}\n\nl4: lists {\nnullableOfNullable \n...InlineListFragment \n}\n\nl5: lists {\n...FragmentWithArgs \n}\n\n}\nfragment FragmentWithArgs on Lists {\nlistWithArg(arg1: $arg1) \n}\nfragment InlineListFragment on Lists {\nnullableOfNullable \nnullableOfNonNullable \n}\nfragment ListFragment on Lists {\nnullableOfNullable \nnullableOfNonNullable \n}\n"; +var query$3 = "query MyQuery($arg1: String) {\nl1: lists {\n...ListFragment \n}\n\nl2: lists {\n...ListFragment \n...ListFragment \n}\n\nl3: lists {\nnullableOfNullable \n...ListFragment \n...ListFragment \n}\n\nl4: lists {\nnullableOfNullable \n...InlineListFragment \n}\n\nl5: lists {\n...FragmentWithArgs \n}\n\n}\nfragment FragmentWithArgs on Lists {\nlistWithArg(arg1: $arg1) \n}\nfragment ListFragment on Lists {\nnullableOfNullable \nnullableOfNonNullable \n}\nfragment InlineListFragment on Lists {\nnullableOfNullable \nnullableOfNonNullable \n}\n"; function parse$5(value) { var value$1 = value.l2; diff --git a/snapshot_tests/operations/expected/records/compile/tagged_template.res.txt b/snapshot_tests/operations/expected/records/compile/tagged_template.res.txt index 1eeb859f..8488ecc7 100644 --- a/snapshot_tests/operations/expected/records/compile/tagged_template.res.txt +++ b/snapshot_tests/operations/expected/records/compile/tagged_template.res.txt @@ -1,6 +1,7 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; +var Gatsby = require("gatsby"); var ApolloClient = require("apollo-client"); function deepMerge(json1, param) { @@ -13,22 +14,22 @@ var Graphql_ppx_runtime = { var Raw = {}; -var query = (graphql` - query { - variousScalars { - nullableString - string - nullableInt - int - nullableFloat - float - nullableBoolean - boolean - nullableID - id - } - } -`); +var query = graphql`query { +variousScalars { +nullableString +string +nullableInt +int +nullableFloat +float +nullableBoolean +boolean +nullableID +id +} + +} +`; function parse(value) { var value$1 = value.variousScalars; @@ -113,22 +114,22 @@ var MyTypes = {}; var Raw$1 = {}; -var query$1 = (graphql` - query { - variousScalars { - nullableString - string - nullableInt - int - nullableFloat - float - nullableBoolean - boolean - nullableID - id - } - } -`); +var query$1 = graphql`query { +variousScalars { +nullableString +string +nullableInt +int +nullableFloat +float +nullableBoolean +boolean +nullableID +id +} + +} +`; function parse$1(value) { var value$1 = value.variousScalars; @@ -211,22 +212,22 @@ var MyQuery1a = { var Raw$2 = {}; -var query$2 = (graphql` - query { - variousScalars { - nullableString - string - nullableInt - int - nullableFloat - float - nullableBoolean - boolean - nullableID - id - } - } -`); +var query$2 = graphql`query { +variousScalars { +nullableString +string +nullableInt +int +nullableFloat +float +nullableBoolean +boolean +nullableID +id +} + +} +`; function parse$2(value) { var value$1 = value.variousScalars; @@ -309,22 +310,22 @@ var MyQuery1b = { var Raw$3 = {}; -var query$3 = (require("gatsby").graphql` - query { - variousScalars { - nullableString - string - nullableInt - int - nullableFloat - float - nullableBoolean - boolean - nullableID - id - } - } -`); +var query$3 = Gatsby.graphql`query { +variousScalars { +nullableString +string +nullableInt +int +nullableFloat +float +nullableBoolean +boolean +nullableID +id +} + +} +`; function parse$3(value) { var value$1 = value.variousScalars; @@ -407,22 +408,22 @@ var MyQuery2 = { var Raw$4 = {}; -var query$4 = (require("gatsby").graphql` - query { - variousScalars { - nullableString - string - nullableInt - int - nullableFloat - float - nullableBoolean - boolean - nullableID - id - } - } -`); +var query$4 = Gatsby.graphql`query { +variousScalars { +nullableString +string +nullableInt +int +nullableFloat +float +nullableBoolean +boolean +nullableID +id +} + +} +`; function parse$4(value) { var value$1 = value.variousScalars; @@ -505,22 +506,22 @@ var MyQuery3 = { var Raw$5 = {}; -var query$5 = (require("gatsby")` - query { - variousScalars { - nullableString - string - nullableInt - int - nullableFloat - float - nullableBoolean - boolean - nullableID - id - } - } -`); +var query$5 = Gatsby.graphql`query { +variousScalars { +nullableString +string +nullableInt +int +nullableFloat +float +nullableBoolean +boolean +nullableID +id +} + +} +`; function parse$5(value) { var value$1 = value.variousScalars; @@ -603,12 +604,11 @@ var MyQuery4 = { var Raw$6 = {}; -var query$6 = (require("gatsby")` - fragment ListFragment on Lists { - nullableOfNullable - nullableOfNonNullable - } -`); +var query$6 = Gatsby.graphql`fragment ListFragment on Lists { +nullableOfNullable +nullableOfNonNullable +} +`; function parse$6(value) { var value$1 = value.nullableOfNullable; @@ -664,13 +664,13 @@ var ListFragment = { var Raw$7 = {}; -var query$7 = (require("gatsby")` - query MyQuery5 { - lists { - ...ListFragment - } - } -`); +var query$7 = Gatsby.graphql`query MyQuery5 { +lists { +...ListFragment +} + +} +${query$6}`; function parse$7(value) { return { @@ -710,14 +710,13 @@ var MyQuery5 = { var Raw$8 = {}; -var query$8 = ((frag_0) => require("gatsby")` - query MyQuery6 { - lists { - ...ListFragment - } - } - ${frag_0} -`)(query$6); +var query$8 = Gatsby.graphql`query MyQuery6 { +lists { +...ListFragment +} + +} +${query$6}`; function parse$8(value) { return { @@ -757,13 +756,13 @@ var MyQuery6 = { var Raw$9 = {}; -var query$9 = (graphql` - query MyQuery7 { - lists { - ...ListFragment - } - } -`); +var query$9 = graphql`query MyQuery7 { +lists { +...ListFragment +} + +} +${query$6}`; function parse$9(value) { return { diff --git a/snapshot_tests/operations/expected/records/generate/fragmentDefinition.res.txt b/snapshot_tests/operations/expected/records/generate/fragmentDefinition.res.txt index fe2f324b..2f312234 100644 --- a/snapshot_tests/operations/expected/records/generate/fragmentDefinition.res.txt +++ b/snapshot_tests/operations/expected/records/generate/fragmentDefinition.res.txt @@ -522,9 +522,9 @@ l5: lists { ", FragmentWithArgs.query, ), - InlineListFragment.query, + ListFragment.query, ), - ListFragment.query, + InlineListFragment.query, ) let parse = (value): t => { l1: { diff --git a/snapshot_tests/operations/expected/records/generate/tagged_template.res.txt b/snapshot_tests/operations/expected/records/generate/tagged_template.res.txt index b30c035c..6c3dd713 100644 --- a/snapshot_tests/operations/expected/records/generate/tagged_template.res.txt +++ b/snapshot_tests/operations/expected/records/generate/tagged_template.res.txt @@ -2,6 +2,9 @@ module Graphql_ppx_runtime = { // mock let deepMerge = (json1, _) => json1 } + +@variadic @taggedTemplate +external graphql: (array, array) => string = "graphql" module MyQuery: { @@ocaml.warning("-32-30") module Raw: { @@ -78,23 +81,26 @@ function back to the original JSON compatible data ") } type rec t = {variousScalars: t_variousScalars} type rec t_variables = unit - let query = ( - %raw("graphql` - query { - variousScalars { - nullableString - string - nullableInt - int - nullableFloat - float - nullableBoolean - boolean - nullableID - id - } - } -`"): string + let query = graphql( + [ + "query { +variousScalars { +nullableString +string +nullableInt +int +nullableFloat +float +nullableBoolean +boolean +nullableID +id +} + +} +", + ], + [], ) let parse = (value): t => { variousScalars: { @@ -248,6 +254,9 @@ function back to the original JSON compatible data ") module MyTypes = { type query } + +@variadic @taggedTemplate +external graphql: (array, array) => MyTypes.query = "graphql" module MyQuery1a: { @@ocaml.warning("-32-30") module Raw: { @@ -324,23 +333,26 @@ function back to the original JSON compatible data ") } type rec t = {variousScalars: t_variousScalars} type rec t_variables = unit - let query = ( - %raw("graphql` - query { - variousScalars { - nullableString - string - nullableInt - int - nullableFloat - float - nullableBoolean - boolean - nullableID - id - } - } -`"): MyTypes.query + let query = graphql( + [ + "query { +variousScalars { +nullableString +string +nullableInt +int +nullableFloat +float +nullableBoolean +boolean +nullableID +id +} + +} +", + ], + [], ) let parse = (value): t => { variousScalars: { @@ -490,6 +502,9 @@ function back to the original JSON compatible data ") external toJson: Raw.t => Js.Json.t = "%identity" external variablesToJson: Raw.t_variables => Js.Json.t = "%identity" } + +@variadic @taggedTemplate +external graphql: (array, array) => string = "graphql" module MyQuery1b: { @@ocaml.warning("-32-30") module Raw: { @@ -566,23 +581,26 @@ function back to the original JSON compatible data ") } type rec t = {variousScalars: t_variousScalars} type rec t_variables = unit - let query = ( - %raw("graphql` - query { - variousScalars { - nullableString - string - nullableInt - int - nullableFloat - float - nullableBoolean - boolean - nullableID - id - } - } -`"): string + let query = graphql( + [ + "query { +variousScalars { +nullableString +string +nullableInt +int +nullableFloat +float +nullableBoolean +boolean +nullableID +id +} + +} +", + ], + [], ) let parse = (value): t => { variousScalars: { @@ -808,23 +826,29 @@ function back to the original JSON compatible data ") } type rec t = {variousScalars: t_variousScalars} type rec t_variables = unit - let query = ( - %raw("require("gatsby").graphql` - query { - variousScalars { - nullableString - string - nullableInt - int - nullableFloat - float - nullableBoolean - boolean - nullableID - id - } - } -`"): string + @module("gatsby") @taggedTemplate + external graphql: (array, array) => string = "graphql" + external graphql_allow_string: string => string = "%identity" + let query = graphql( + [ + "query { +variousScalars { +nullableString +string +nullableInt +int +nullableFloat +float +nullableBoolean +boolean +nullableID +id +} + +} +", + ], + [], ) let parse = (value): t => { variousScalars: { @@ -1050,23 +1074,29 @@ function back to the original JSON compatible data ") } type rec t = {variousScalars: t_variousScalars} type rec t_variables = unit - let query = ( - %raw("require("gatsby").graphql` - query { - variousScalars { - nullableString - string - nullableInt - int - nullableFloat - float - nullableBoolean - boolean - nullableID - id - } - } -`"): string + @module("gatsby") @taggedTemplate + external graphql: (array, array) => string = "graphql" + external graphql_allow_string: string => string = "%identity" + let query = graphql( + [ + "query { +variousScalars { +nullableString +string +nullableInt +int +nullableFloat +float +nullableBoolean +boolean +nullableID +id +} + +} +", + ], + [], ) let parse = (value): t => { variousScalars: { @@ -1292,23 +1322,29 @@ function back to the original JSON compatible data ") } type rec t = {variousScalars: t_variousScalars} type rec t_variables = unit - let query = ( - %raw("require("gatsby")` - query { - variousScalars { - nullableString - string - nullableInt - int - nullableFloat - float - nullableBoolean - boolean - nullableID - id - } - } -`"): string + @module("gatsby") @taggedTemplate + external graphql: (array, array) => string = "graphql" + external graphql_allow_string: string => string = "%identity" + let query = graphql( + [ + "query { +variousScalars { +nullableString +string +nullableInt +int +nullableFloat +float +nullableBoolean +boolean +nullableID +id +} + +} +", + ], + [], ) let parse = (value): t => { variousScalars: { @@ -1496,13 +1532,18 @@ function back to the original JSON-compatible data ") nullableOfNonNullable: option>, } type t_Lists = t - let query = ( - %raw("require("gatsby")` - fragment ListFragment on Lists { - nullableOfNullable - nullableOfNonNullable - } -`"): string + @module("gatsby") @taggedTemplate + external graphql: (array, array) => string = "graphql" + external graphql_allow_string: string => string = "%identity" + let query = graphql( + [ + "fragment ListFragment on Lists { +nullableOfNullable +nullableOfNonNullable +} +", + ], + [], ) let parse = ( (value): t => { @@ -1593,14 +1634,21 @@ function back to the original JSON compatible data ") } type rec t = {lists: ListFragment.t_Lists} type rec t_variables = unit - let query = ( - %raw("require("gatsby")` - query MyQuery5 { - lists { - ...ListFragment - } - } -`"): string + @module("gatsby") @taggedTemplate + external graphql: (array, array) => string = "graphql" + external graphql_allow_string: string => string = "%identity" + let query = graphql( + [ + "query MyQuery5 { +lists { +...ListFragment +} + +} +", + "", + ], + [ListFragment.query], ) let parse = (value): t => { lists: { @@ -1651,15 +1699,21 @@ function back to the original JSON compatible data ") } type rec t = {lists: ListFragment.t_Lists} type rec t_variables = unit - let query = ( - %raw("(frag_0) => require("gatsby")` - query MyQuery6 { - lists { - ...ListFragment - } - } - ${frag_0} -`")(ListFragment.query): string + @module("gatsby") @taggedTemplate + external graphql: (array, array) => string = "graphql" + external graphql_allow_string: string => string = "%identity" + let query = graphql( + [ + "query MyQuery6 { +lists { +...ListFragment +} + +} +", + "", + ], + [ListFragment.query], ) let parse = (value): t => { lists: { @@ -1710,14 +1764,18 @@ function back to the original JSON compatible data ") } type rec t = {lists: ListFragment.t_Lists} type rec t_variables = unit - let query = ( - %raw("graphql` - query MyQuery7 { - lists { - ...ListFragment - } - } -`"): string + let query = graphql( + [ + "query MyQuery7 { +lists { +...ListFragment +} + +} +", + "", + ], + [ListFragment.query], ) let parse = (value): t => { lists: { @@ -1778,14 +1836,17 @@ function back to the original JSON-compatible data ") nullableOfNonNullable: option>, } type t_Lists = t - @module("apollo-client") external graphql: array => int = "gql" - let query = graphql([ - "fragment ListFragment8 on Lists { + @module("apollo-client") @variadic external gql: (array, array) => int = "gql" + let query = gql( + [ + "fragment ListFragment8 on Lists { nullableOfNullable nullableOfNonNullable } ", - ]) + ], + [], + ) let parse = ( (value): t => { nullableOfNullable: { @@ -1932,8 +1993,8 @@ function back to the original JSON compatible data ") variousScalars: t_variousScalars, } type rec t_variables = unit - @module("apollo-client") external graphql: (array, int) => int = "gql" - let query = graphql( + @module("apollo-client") @variadic external gql: (array, array) => int = "gql" + let query = gql( [ "query MyQuery8 { lists { @@ -1957,7 +2018,7 @@ id ", "", ], - ListFragment8.query, + [ListFragment8.query], ) let parse = (value): t => { lists: { diff --git a/snapshot_tests/operations/expected/template/compile/argNamedQuery.res.txt b/snapshot_tests/operations/expected/template/compile/argNamedQuery.res.txt index aac1f29f..d22398dc 100644 --- a/snapshot_tests/operations/expected/template/compile/argNamedQuery.res.txt +++ b/snapshot_tests/operations/expected/template/compile/argNamedQuery.res.txt @@ -1,14 +1,14 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; +var Gql = require("gql").default; var Raw = {}; -var query = (require("gql")` - query ($query: Int!) { - argNamedQuery(query: $query) - } -`); +var query = Gql`query ($query: Int!) { +argNamedQuery(query: $query) +} +`; function parse(value) { return { @@ -46,11 +46,10 @@ var MyQuery = { var Raw$1 = {}; -var query$1 = (require("gql")` - query Query1($query: Int!) { - argNamedQuery(query: $query) - } -`); +var query$1 = Gql`query Query1($query: Int!) { +argNamedQuery(query: $query) +} +`; function parse$1(value) { return { @@ -88,11 +87,10 @@ var Query1 = { var Raw$2 = {}; -var query$2 = (require("gql")` - query Query2($query: Int!) { - argNamedQuery(query: $query) - } -`); +var query$2 = Gql`query Query2($query: Int!) { +argNamedQuery(query: $query) +} +`; function parse$2(value) { return { diff --git a/snapshot_tests/operations/expected/template/compile/comment.res.txt b/snapshot_tests/operations/expected/template/compile/comment.res.txt index c6465465..1d9c177d 100644 --- a/snapshot_tests/operations/expected/template/compile/comment.res.txt +++ b/snapshot_tests/operations/expected/template/compile/comment.res.txt @@ -1,14 +1,14 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; +var Gql = require("gql").default; var Raw = {}; -var query = (require("gql")` - query ($arg: NonrecursiveInput!) { - nonrecursiveInput(arg: $arg) - } -`); +var query = Gql`query ($arg: NonrecursiveInput!) { +nonrecursiveInput(arg: $arg) +} +`; function parse(value) { return { diff --git a/snapshot_tests/operations/expected/template/compile/customDecoder.res.txt b/snapshot_tests/operations/expected/template/compile/customDecoder.res.txt index dbba9346..cdb10268 100644 --- a/snapshot_tests/operations/expected/template/compile/customDecoder.res.txt +++ b/snapshot_tests/operations/expected/template/compile/customDecoder.res.txt @@ -1,6 +1,7 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; +var Gql = require("gql").default; var Caml_format = require("rescript/lib/js/caml_format.js"); function parse(prim) { @@ -27,14 +28,14 @@ var IntOfString = { var Raw = {}; -var query = (require("gql")` - query { - variousScalars { - string - int - } - } -`); +var query = Gql`query { +variousScalars { +string +int +} + +} +`; function parse$2(value) { var value$1 = value.variousScalars; diff --git a/snapshot_tests/operations/expected/template/compile/customScalars.res.txt b/snapshot_tests/operations/expected/template/compile/customScalars.res.txt index 60a6ef10..5c5f1e75 100644 --- a/snapshot_tests/operations/expected/template/compile/customScalars.res.txt +++ b/snapshot_tests/operations/expected/template/compile/customScalars.res.txt @@ -1,17 +1,18 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; +var Gql = require("gql").default; var Raw = {}; -var query = (require("gql")` - query ($opt: CustomScalar, $req: CustomScalar!) { - customScalarField(argOptional: $opt, argRequired: $req) { - nullable - nonNullable - } - } -`); +var query = Gql`query ($opt: CustomScalar, $req: CustomScalar!) { +customScalarField(argOptional: $opt, argRequired: $req) { +nullable +nonNullable +} + +} +`; function parse(value) { var value$1 = value.customScalarField; diff --git a/snapshot_tests/operations/expected/template/compile/customTypes.res.txt b/snapshot_tests/operations/expected/template/compile/customTypes.res.txt index f33fc26f..12bb2879 100644 --- a/snapshot_tests/operations/expected/template/compile/customTypes.res.txt +++ b/snapshot_tests/operations/expected/template/compile/customTypes.res.txt @@ -1,6 +1,7 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; +var Gql = require("gql").default; var Js_json = require("rescript/lib/js/js_json.js"); var Caml_option = require("rescript/lib/js/caml_option.js"); @@ -87,17 +88,17 @@ var DateTime = { var Raw = {}; -var query = (require("gql")` - query { - customFields { - currentTime - favoriteColor - futureTime - nullableColor - nullableString - } - } -`); +var query = Gql`query { +customFields { +currentTime +favoriteColor +futureTime +nullableColor +nullableString +} + +} +`; function parse$3(value) { var value$1 = value.customFields; diff --git a/snapshot_tests/operations/expected/template/compile/defaultObjectValueOnScalar.res.txt b/snapshot_tests/operations/expected/template/compile/defaultObjectValueOnScalar.res.txt index 9e7af7c2..f1587679 100644 --- a/snapshot_tests/operations/expected/template/compile/defaultObjectValueOnScalar.res.txt +++ b/snapshot_tests/operations/expected/template/compile/defaultObjectValueOnScalar.res.txt @@ -1,14 +1,14 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; +var Gql = require("gql").default; var Raw = {}; -var query = (require("gql")` - query { - defaultObjectValueOnScalar(filter: {some: {json: "value"}}, arg: {field: "otherValue"}) - } -`); +var query = Gql`query { +defaultObjectValueOnScalar(filter: {some: {json: "value"}}, arg: {field: "otherValue"}) +} +`; function parse(value) { return { diff --git a/snapshot_tests/operations/expected/template/compile/enumInput.res.txt b/snapshot_tests/operations/expected/template/compile/enumInput.res.txt index b2dbee9a..2491c2b0 100644 --- a/snapshot_tests/operations/expected/template/compile/enumInput.res.txt +++ b/snapshot_tests/operations/expected/template/compile/enumInput.res.txt @@ -1,14 +1,14 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; +var Gql = require("gql").default; var Raw = {}; -var query = (require("gql")` - query ($arg: SampleField!) { - enumInput(arg: $arg) - } -`); +var query = Gql`query ($arg: SampleField!) { +enumInput(arg: $arg) +} +`; function parse(value) { return { diff --git a/snapshot_tests/operations/expected/template/compile/ewert_reproduction.res.txt b/snapshot_tests/operations/expected/template/compile/ewert_reproduction.res.txt index dd4ce1ff..726802d5 100644 --- a/snapshot_tests/operations/expected/template/compile/ewert_reproduction.res.txt +++ b/snapshot_tests/operations/expected/template/compile/ewert_reproduction.res.txt @@ -1,18 +1,19 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; +var Gql = require("gql").default; var Raw = {}; -var query = (require("gql")` - fragment UserData on Workspace { - user(id: $userId) { - id - firstname - lastname - } - } -`); +var query = Gql`fragment UserData on Workspace { +user(id: $userId) { +id +firstname +lastname +} + +} +`; function parse(value) { var value$1 = value.user; diff --git a/snapshot_tests/operations/expected/template/compile/explicit_object_record.res.txt b/snapshot_tests/operations/expected/template/compile/explicit_object_record.res.txt index 44fb7a87..fcb9f2ae 100644 --- a/snapshot_tests/operations/expected/template/compile/explicit_object_record.res.txt +++ b/snapshot_tests/operations/expected/template/compile/explicit_object_record.res.txt @@ -1,19 +1,20 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; +var Gql = require("gql").default; var Raw = {}; -var query = (require("gql")` - query { - lists { - nullableOfNullable - nullableOfNonNullable - nonNullableOfNullable - nonNullableOfNonNullable - } - } -`); +var query = Gql`query { +lists { +nullableOfNullable +nullableOfNonNullable +nonNullableOfNullable +nonNullableOfNonNullable +} + +} +`; function parse(value) { var value$1 = value.lists; @@ -106,16 +107,16 @@ var RecordsQuery = { var Raw$1 = {}; -var query$1 = (require("gql")` - query { - lists { - nullableOfNullable - nullableOfNonNullable - nonNullableOfNullable - nonNullableOfNonNullable - } - } -`); +var query$1 = Gql`query { +lists { +nullableOfNullable +nullableOfNonNullable +nonNullableOfNullable +nonNullableOfNonNullable +} + +} +`; function parse$1(value) { var value$1 = value.lists; diff --git a/snapshot_tests/operations/expected/template/compile/extensions.res.txt b/snapshot_tests/operations/expected/template/compile/extensions.res.txt index 1c221648..83cc4c03 100644 --- a/snapshot_tests/operations/expected/template/compile/extensions.res.txt +++ b/snapshot_tests/operations/expected/template/compile/extensions.res.txt @@ -1,6 +1,7 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; +var Gql = require("gql").default; function ExtendQuery(M) { var use = function (param) { @@ -17,16 +18,16 @@ var Parent = { var Raw = {}; -var query = (require("gql")` - query Bla { - lists { - nullableOfNullable - nullableOfNonNullable - nonNullableOfNullable - nonNullableOfNonNullable - } - } -`); +var query = Gql`query Bla { +lists { +nullableOfNullable +nullableOfNonNullable +nonNullableOfNullable +nonNullableOfNonNullable +} + +} +`; function parse(value) { var value$1 = value.lists; @@ -135,16 +136,16 @@ var Bla = { var Raw$1 = {}; -var query$1 = (require("gql")` - query Bla2 { - lists { - nullableOfNullable - nullableOfNonNullable - nonNullableOfNullable - nonNullableOfNonNullable - } - } -`); +var query$1 = Gql`query Bla2 { +lists { +nullableOfNullable +nullableOfNonNullable +nonNullableOfNullable +nonNullableOfNonNullable +} + +} +`; function parse$1(value) { var value$1 = value.lists; diff --git a/snapshot_tests/operations/expected/template/compile/fragmentDefinition.res.txt b/snapshot_tests/operations/expected/template/compile/fragmentDefinition.res.txt index 100a655b..e385d273 100644 --- a/snapshot_tests/operations/expected/template/compile/fragmentDefinition.res.txt +++ b/snapshot_tests/operations/expected/template/compile/fragmentDefinition.res.txt @@ -1,6 +1,7 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; +var Gql = require("gql").default; function deepMerge(json1, param) { return json1; @@ -12,12 +13,11 @@ var Graphql_ppx_runtime = { var Raw = {}; -var query = (require("gql")` - fragment ListFragment on Lists { - nullableOfNullable - nullableOfNonNullable - } -`); +var query = Gql`fragment ListFragment on Lists { +nullableOfNullable +nullableOfNonNullable +} +`; function parse(value) { var value$1 = value.nullableOfNullable; @@ -73,11 +73,10 @@ var ListFragment = { var Raw$1 = {}; -var query$1 = (require("gql")` - fragment Another on Lists { - nullableOfNonNullable - } -`); +var query$1 = Gql`fragment Another on Lists { +nullableOfNonNullable +} +`; function parse$1(value) { var value$1 = value.nullableOfNonNullable; @@ -117,11 +116,10 @@ var Another = { var Raw$2 = {}; -var query$2 = (require("gql")` - fragment FragmentWithArgs on Lists { - listWithArg(arg1: $arg1) - } -`); +var query$2 = Gql`fragment FragmentWithArgs on Lists { +listWithArg(arg1: $arg1) +} +`; function parse$2(value) { var value$1 = value.listWithArg; @@ -168,12 +166,11 @@ var FragmentWithArgs = { var Raw$3 = {}; -var query$3 = (require("gql")` - fragment InlineListFragment on Lists { - nullableOfNullable - nullableOfNonNullable - } -`); +var query$3 = Gql`fragment InlineListFragment on Lists { +nullableOfNullable +nullableOfNonNullable +} +`; function parse$3(value) { var value$1 = value.nullableOfNullable; @@ -229,12 +226,11 @@ var InlineListFragment = { var Raw$4 = {}; -var query$4 = (require("gql")` - fragment InlineListFragment on Lists { - nullableOfNullable - nullableOfNonNullable - } -`); +var query$4 = Gql`fragment InlineListFragment on Lists { +nullableOfNullable +nullableOfNonNullable +} +`; function parse$4(value) { var value$1 = value.nullableOfNullable; @@ -290,32 +286,33 @@ var Wrapper = { var Raw$5 = {}; -var query$5 = ((frag_0, frag_1, frag_2) => require("gql")` - query MyQuery($arg1: String) { - l1: lists { - ...ListFragment - } - l2: lists { - ...ListFragment - ...ListFragment - } - l3: lists { - nullableOfNullable - ...ListFragment - ...ListFragment - } - l4: lists { - nullableOfNullable - ...InlineListFragment - } - l5: lists { - ...FragmentWithArgs - } - } - ${frag_0} - ${frag_1} - ${frag_2} -`)(query$2, query$3, query); +var query$5 = Gql`query MyQuery($arg1: String) { +l1: lists { +...ListFragment +} + +l2: lists { +...ListFragment +...ListFragment +} + +l3: lists { +nullableOfNullable +...ListFragment +...ListFragment +} + +l4: lists { +nullableOfNullable +...InlineListFragment +} + +l5: lists { +...FragmentWithArgs +} + +} +${query$2}${query}${query$3}`; function parse$5(value) { var value$1 = value.l2; @@ -429,14 +426,13 @@ var MyQuery = { var Raw$6 = {}; -var query$6 = ((frag_0) => require("gql")` - query { - lists { - ...ListFragment - } - } - ${frag_0} -`)(query); +var query$6 = Gql`query { +lists { +...ListFragment +} + +} +${query}`; function parse$6(value) { return { diff --git a/snapshot_tests/operations/expected/template/compile/fragmentInFragment.res.txt b/snapshot_tests/operations/expected/template/compile/fragmentInFragment.res.txt index 389946dd..8f04cc15 100644 --- a/snapshot_tests/operations/expected/template/compile/fragmentInFragment.res.txt +++ b/snapshot_tests/operations/expected/template/compile/fragmentInFragment.res.txt @@ -1,6 +1,7 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; +var Gql = require("gql").default; function deepMerge(json1, param) { return json1; @@ -12,11 +13,10 @@ var Graphql_ppx_runtime = { var Raw = {}; -var query = (require("gql")` - fragment ListFragment on Lists { - nullableOfNullable - } -`); +var query = Gql`fragment ListFragment on Lists { +nullableOfNullable +} +`; function parse(value) { var value$1 = value.nullableOfNullable; @@ -63,13 +63,11 @@ var ListFragment = { var Raw$1 = {}; -var query$1 = ((frag_0) => require("gql")` - fragment Another on Lists { - nullableOfNullable - ...ListFragment - } - ${frag_0} -`)(query); +var query$1 = Gql`fragment Another on Lists { +nullableOfNullable +...ListFragment +} +${query}`; function parse$1(value) { var value$1 = value["nullableOfNullable"]; diff --git a/snapshot_tests/operations/expected/template/compile/fragmentOnInterface.res.txt b/snapshot_tests/operations/expected/template/compile/fragmentOnInterface.res.txt index 54146408..19068fc7 100644 --- a/snapshot_tests/operations/expected/template/compile/fragmentOnInterface.res.txt +++ b/snapshot_tests/operations/expected/template/compile/fragmentOnInterface.res.txt @@ -1,6 +1,7 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; +var Gql = require("gql").default; function deepMerge(json1, param) { return json1; @@ -12,12 +13,11 @@ var Graphql_ppx_runtime = { var Raw = {}; -var query = (require("gql")` - fragment InterfaceFragment on User { - __typename - id - } -`); +var query = Gql`fragment InterfaceFragment on User { +__typename +id +} +`; function parse(value) { return { @@ -53,14 +53,12 @@ var InterfaceFragment = { var Raw$1 = {}; -var query$1 = ((frag_0) => require("gql")` - fragment AnotherFragment on User { - __typename - id - ...InterfaceFragment - } - ${frag_0} -`)(query); +var query$1 = Gql`fragment AnotherFragment on User { +__typename +id +...InterfaceFragment +} +${query}`; function parse$1(value) { return { @@ -96,13 +94,11 @@ var AnotherFragment = { var Raw$2 = {}; -var query$2 = ((frag_0) => require("gql")` - fragment AnonUser on AnonymousUser { - id - ...InterfaceFragment - } - ${frag_0} -`)(query); +var query$2 = Gql`fragment AnonUser on AnonymousUser { +id +...InterfaceFragment +} +${query}`; function parse$2(value) { return { diff --git a/snapshot_tests/operations/expected/template/compile/fragmentUnion.res.txt b/snapshot_tests/operations/expected/template/compile/fragmentUnion.res.txt index 0222e591..d1efc193 100644 --- a/snapshot_tests/operations/expected/template/compile/fragmentUnion.res.txt +++ b/snapshot_tests/operations/expected/template/compile/fragmentUnion.res.txt @@ -1,6 +1,7 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; +var Gql = require("gql").default; var assign_typename = ((obj, typename) => { obj.__typename = typename; return obj }); @@ -10,11 +11,10 @@ var Graphql_ppx_runtime = { var Raw = {}; -var query = (require("gql")` - fragment DogFragment on Dog { - name - } -`); +var query = Gql`fragment DogFragment on Dog { +name +} +`; function parse(value) { return { @@ -50,11 +50,10 @@ var DogFragment = { var Raw$1 = {}; -var query$1 = (require("gql")` - fragment HumanFragment on Human { - name - } -`); +var query$1 = Gql`fragment HumanFragment on Human { +name +} +`; function parse$1(value) { return { @@ -90,21 +89,21 @@ var HumanFragment = { var Raw$2 = {}; -var query$2 = ((frag_0, frag_1) => require("gql")` - query MyQuery { - dogOrHuman { - __typename - ...on Dog { - ...DogFragment - } - ...on Human { - ...HumanFragment - } - } - } - ${frag_0} - ${frag_1} -`)(query, query$1); +var query$2 = Gql`query MyQuery { +dogOrHuman { +__typename +...on Dog { +...DogFragment +} + +...on Human { +...HumanFragment +} + +} + +} +${query}${query$1}`; function parse$2(value) { var value$1 = value.dogOrHuman; diff --git a/snapshot_tests/operations/expected/template/compile/fragmentvariableinput.res.txt b/snapshot_tests/operations/expected/template/compile/fragmentvariableinput.res.txt index 45e464d6..a8328ee6 100644 --- a/snapshot_tests/operations/expected/template/compile/fragmentvariableinput.res.txt +++ b/snapshot_tests/operations/expected/template/compile/fragmentvariableinput.res.txt @@ -1,16 +1,17 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; +var Gql = require("gql").default; var Raw = {}; -var query = (require("gql")` - fragment test on Post { - reposts(arg: {name: $name}) { - id - } - } -`); +var query = Gql`fragment test on Post { +reposts(arg: {name: $name}) { +id +} + +} +`; function parse(value) { var value$1 = value.reposts; diff --git a/snapshot_tests/operations/expected/template/compile/hasuraRepro.res.txt b/snapshot_tests/operations/expected/template/compile/hasuraRepro.res.txt index e7f65e80..702b15ba 100644 --- a/snapshot_tests/operations/expected/template/compile/hasuraRepro.res.txt +++ b/snapshot_tests/operations/expected/template/compile/hasuraRepro.res.txt @@ -1,14 +1,14 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; +var Gql = require("gql").default; var Raw = {}; -var query = (require("gql")` - fragment Dog on Dog { - name - } -`); +var query = Gql`fragment Dog on Dog { +name +} +`; function parse(value) { return { @@ -44,14 +44,13 @@ var Dog = { var Raw$1 = {}; -var query$1 = ((frag_0) => require("gql")` - query HasuraRepro($blockNumber: Int, $type: String) { - hasuraRepro(orderBy: [{id: desc}], block: {number: $blockNumber, type: $type}) { - ...Dog - } - } - ${frag_0} -`)(query); +var query$1 = Gql`query HasuraRepro($blockNumber: Int, $type: String) { +hasuraRepro(orderBy: [{id: desc}], block: {number: $blockNumber, type: $type}) { +...Dog +} + +} +${query}`; function parse$1(value) { var value$1 = value.hasuraRepro; diff --git a/snapshot_tests/operations/expected/template/compile/interface.res.txt b/snapshot_tests/operations/expected/template/compile/interface.res.txt index 848e3f3a..b3b79ea6 100644 --- a/snapshot_tests/operations/expected/template/compile/interface.res.txt +++ b/snapshot_tests/operations/expected/template/compile/interface.res.txt @@ -1,6 +1,7 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; +var Gql = require("gql").default; function deepMerge(json1, param) { return json1; @@ -12,21 +13,23 @@ var Graphql_ppx_runtime = { var Raw = {}; -var query = (require("gql")` - query { - users { - __typename - ...on AdminUser { - id - name - } - ...on AnonymousUser { - id - anonymousId - } - } - } -`); +var query = Gql`query { +users { +__typename +...on AdminUser { +id +name +} + +...on AnonymousUser { +id +anonymousId +} + +} + +} +`; function parse(value) { var value$1 = value.users; @@ -115,17 +118,18 @@ var QueryWithOnlyFragments = { var Raw$1 = {}; -var query$1 = (require("gql")` - query { - users { - __typename - ...on AdminUser { - __typename - id - } - } - } -`); +var query$1 = Gql`query { +users { +__typename +...on AdminUser { +__typename +id +} + +} + +} +`; function parse$1(value) { var value$1 = value.users; @@ -191,20 +195,22 @@ var QueryWithTypename = { var Raw$2 = {}; -var query$2 = (require("gql")` - query { - users { - __typename - id - ...on AdminUser { - name - } - ...on AnonymousUser { - anonymousId - } - } - } -`); +var query$2 = Gql`query { +users { +__typename +id +...on AdminUser { +name +} + +...on AnonymousUser { +anonymousId +} + +} + +} +`; function parse$2(value) { var value$1 = value.users; @@ -297,19 +303,20 @@ var QueryWithMixedFragments = { var Raw$3 = {}; -var query$3 = (require("gql")` - query { - users { - __typename - id - __typename - ...on AdminUser { - __typename - id - } - } - } -`); +var query$3 = Gql`query { +users { +__typename +id +__typename +...on AdminUser { +__typename +id +} + +} + +} +`; function parse$3(value) { var value$1 = value.users; @@ -385,14 +392,14 @@ var MixedQueryWithTypename = { var Raw$4 = {}; -var query$4 = (require("gql")` - query { - users { - __typename - id - } - } -`); +var query$4 = Gql`query { +users { +__typename +id +} + +} +`; function parse$4(value) { var value$1 = value.users; diff --git a/snapshot_tests/operations/expected/template/compile/lists.res.txt b/snapshot_tests/operations/expected/template/compile/lists.res.txt index cd01ccb5..b1921d0d 100644 --- a/snapshot_tests/operations/expected/template/compile/lists.res.txt +++ b/snapshot_tests/operations/expected/template/compile/lists.res.txt @@ -1,19 +1,20 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; +var Gql = require("gql").default; var Raw = {}; -var query = (require("gql")` - query { - lists { - nullableOfNullable - nullableOfNonNullable - nonNullableOfNullable - nonNullableOfNonNullable - } - } -`); +var query = Gql`query { +lists { +nullableOfNullable +nullableOfNonNullable +nonNullableOfNullable +nonNullableOfNonNullable +} + +} +`; function parse(value) { var value$1 = value.lists; diff --git a/snapshot_tests/operations/expected/template/compile/listsArgs.res.txt b/snapshot_tests/operations/expected/template/compile/listsArgs.res.txt index b01bbbd5..753b9ef8 100644 --- a/snapshot_tests/operations/expected/template/compile/listsArgs.res.txt +++ b/snapshot_tests/operations/expected/template/compile/listsArgs.res.txt @@ -1,14 +1,14 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; +var Gql = require("gql").default; var Raw = {}; -var query = (require("gql")` - query ($nullableOfNullable: [String], $nullableOfNonNullable: [String!], $nonNullableOfNullable: [String]!, $nonNullableOfNonNullable: [String!]!) { - listsInput(arg: {nullableOfNullable: $nullableOfNullable, nullableOfNonNullable: $nullableOfNonNullable, nonNullableOfNullable: $nonNullableOfNullable, nonNullableOfNonNullable: $nonNullableOfNonNullable}) - } -`); +var query = Gql`query ($nullableOfNullable: [String], $nullableOfNonNullable: [String!], $nonNullableOfNullable: [String]!, $nonNullableOfNonNullable: [String!]!) { +listsInput(arg: {nullableOfNullable: $nullableOfNullable, nullableOfNonNullable: $nullableOfNonNullable, nonNullableOfNullable: $nonNullableOfNullable, nonNullableOfNonNullable: $nonNullableOfNonNullable}) +} +`; function parse(value) { return { diff --git a/snapshot_tests/operations/expected/template/compile/listsInput.res.txt b/snapshot_tests/operations/expected/template/compile/listsInput.res.txt index bffdaff2..b4377c01 100644 --- a/snapshot_tests/operations/expected/template/compile/listsInput.res.txt +++ b/snapshot_tests/operations/expected/template/compile/listsInput.res.txt @@ -1,14 +1,14 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; +var Gql = require("gql").default; var Raw = {}; -var query = (require("gql")` - query ($arg: ListsInput!) { - listsInput(arg: $arg) - } -`); +var query = Gql`query ($arg: ListsInput!) { +listsInput(arg: $arg) +} +`; function parse(value) { return { diff --git a/snapshot_tests/operations/expected/template/compile/module_type.res.txt b/snapshot_tests/operations/expected/template/compile/module_type.res.txt index e9d43ee2..fc6ab6b3 100644 --- a/snapshot_tests/operations/expected/template/compile/module_type.res.txt +++ b/snapshot_tests/operations/expected/template/compile/module_type.res.txt @@ -1,26 +1,11 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; +var Gql = require("gql").default; var Curry = require("rescript/lib/js/curry.js"); -((require("gql")` - query { - variousScalars { - string - } - } -`)); - var MyQuery = {}; -((require("gql")` - query { - variousScalars { - string - } - } -`)); - var MyQuery2 = {}; function parse(nestedObject) { @@ -42,17 +27,19 @@ var VariousScalars = { var Raw = {}; -var query = (require("gql")` - query { - nestedObject { - inner { - inner { - field - } - } - } - } -`); +var query = Gql`query { +nestedObject { +inner { +inner { +field +} + +} + +} + +} +`; function parse$1(value) { var value$1 = value.nestedObject; diff --git a/snapshot_tests/operations/expected/template/compile/mutation.res.txt b/snapshot_tests/operations/expected/template/compile/mutation.res.txt index c58e94b9..ea994d35 100644 --- a/snapshot_tests/operations/expected/template/compile/mutation.res.txt +++ b/snapshot_tests/operations/expected/template/compile/mutation.res.txt @@ -1,22 +1,25 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; +var Gql = require("gql").default; var Raw = {}; -var query = (require("gql")` - mutation { - mutationWithError { - value { - stringField - } - errors { - field - message - } - } - } -`); +var query = Gql`mutation { +mutationWithError { +value { +stringField +} + +errors { +field +message +} + +} + +} +`; function parse(value) { var value$1 = value.mutationWithError; diff --git a/snapshot_tests/operations/expected/template/compile/mutationWithArgs.res.txt b/snapshot_tests/operations/expected/template/compile/mutationWithArgs.res.txt index 5b152778..a7e83b3c 100644 --- a/snapshot_tests/operations/expected/template/compile/mutationWithArgs.res.txt +++ b/snapshot_tests/operations/expected/template/compile/mutationWithArgs.res.txt @@ -1,14 +1,14 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; +var Gql = require("gql").default; var Raw = {}; -var query = (require("gql")` - mutation MyMutation($required: String!) { - optionalInputArgs(required: $required, anotherRequired: "val") - } -`); +var query = Gql`mutation MyMutation($required: String!) { +optionalInputArgs(required: $required, anotherRequired: "val") +} +`; function parse(value) { return { diff --git a/snapshot_tests/operations/expected/template/compile/mutationWithArgsAndNoRecords.res.txt b/snapshot_tests/operations/expected/template/compile/mutationWithArgsAndNoRecords.res.txt index 5b152778..a7e83b3c 100644 --- a/snapshot_tests/operations/expected/template/compile/mutationWithArgsAndNoRecords.res.txt +++ b/snapshot_tests/operations/expected/template/compile/mutationWithArgsAndNoRecords.res.txt @@ -1,14 +1,14 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; +var Gql = require("gql").default; var Raw = {}; -var query = (require("gql")` - mutation MyMutation($required: String!) { - optionalInputArgs(required: $required, anotherRequired: "val") - } -`); +var query = Gql`mutation MyMutation($required: String!) { +optionalInputArgs(required: $required, anotherRequired: "val") +} +`; function parse(value) { return { diff --git a/snapshot_tests/operations/expected/template/compile/nested.res.txt b/snapshot_tests/operations/expected/template/compile/nested.res.txt index 091208f0..803292fd 100644 --- a/snapshot_tests/operations/expected/template/compile/nested.res.txt +++ b/snapshot_tests/operations/expected/template/compile/nested.res.txt @@ -1,35 +1,44 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; +var Gql = require("gql").default; var Raw = {}; -var query = (require("gql")` - query { - first: nestedObject { - inner { - inner { - field - } - } - } - second: nestedObject { - inner { - inner { - f1: field - f2: field - } - } - } - let: nestedObject { - inner { - inner { - field - } - } - } - } -`); +var query = Gql`query { +first: nestedObject { +inner { +inner { +field +} + +} + +} + +second: nestedObject { +inner { +inner { +f1: field +f2: field +} + +} + +} + +let: nestedObject { +inner { +inner { +field +} + +} + +} + +} +`; function parse(value) { var value$1 = value.first; @@ -188,17 +197,19 @@ var MyQuery = { var Raw$1 = {}; -var query$1 = (require("gql")` - query { - nestedObject { - inner { - inner { - field - } - } - } - } -`); +var query$1 = Gql`query { +nestedObject { +inner { +inner { +field +} + +} + +} + +} +`; function parse$1(value) { var value$1 = value.nestedObject; @@ -278,17 +289,19 @@ var Test = { var Raw$2 = {}; -var query$2 = (require("gql")` - query { - nestedObject { - inner { - inner { - field - } - } - } - } -`); +var query$2 = Gql`query { +nestedObject { +inner { +inner { +field +} + +} + +} + +} +`; function parse$2(value) { var value$1 = value.nestedObject; diff --git a/snapshot_tests/operations/expected/template/compile/nonrecursiveInput.res.txt b/snapshot_tests/operations/expected/template/compile/nonrecursiveInput.res.txt index c7fd281f..bb2bb0a6 100644 --- a/snapshot_tests/operations/expected/template/compile/nonrecursiveInput.res.txt +++ b/snapshot_tests/operations/expected/template/compile/nonrecursiveInput.res.txt @@ -1,14 +1,14 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; +var Gql = require("gql").default; var Raw = {}; -var query = (require("gql")` - query ($arg: NonrecursiveInput!) { - nonrecursiveInput(arg: $arg) - } -`); +var query = Gql`query ($arg: NonrecursiveInput!) { +nonrecursiveInput(arg: $arg) +} +`; function parse(value) { return { @@ -104,12 +104,11 @@ var MyQuery = { var Raw$1 = {}; -var query$1 = (require("gql")` - query ($arg: NonrecursiveInput!, $arg2: NonrecursiveInput!) { - scalarsInput(arg: $arg) - more: scalarsInput(arg: $arg2) - } -`); +var query$1 = Gql`query ($arg: NonrecursiveInput!, $arg2: NonrecursiveInput!) { +scalarsInput(arg: $arg) +more: scalarsInput(arg: $arg2) +} +`; function parse$1(value) { return { diff --git a/snapshot_tests/operations/expected/template/compile/omitFutureValueEnum.res.txt b/snapshot_tests/operations/expected/template/compile/omitFutureValueEnum.res.txt index c1861d29..09155c62 100644 --- a/snapshot_tests/operations/expected/template/compile/omitFutureValueEnum.res.txt +++ b/snapshot_tests/operations/expected/template/compile/omitFutureValueEnum.res.txt @@ -1,19 +1,21 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; +var Gql = require("gql").default; var Raw = {}; -var query = (require("gql")` - mutation { - mutationWithError { - errors { - message - field - } - } - } -`); +var query = Gql`mutation { +mutationWithError { +errors { +message +field +} + +} + +} +`; function parse(value) { var value$1 = value.mutationWithError; @@ -96,16 +98,17 @@ var Normal = { var Raw$1 = {}; -var query$1 = (require("gql")` - mutation { - mutationWithError { - errors { - message - field - } - } - } -`); +var query$1 = Gql`mutation { +mutationWithError { +errors { +message +field +} + +} + +} +`; function parse$1(value) { var value$1 = value.mutationWithError; @@ -186,16 +189,17 @@ var ByConfig = { var Raw$2 = {}; -var query$2 = (require("gql")` - mutation { - mutationWithError { - errors { - message - field - } - } - } -`); +var query$2 = Gql`mutation { +mutationWithError { +errors { +message +field +} + +} + +} +`; function parse$2(value) { var value$1 = value.mutationWithError; diff --git a/snapshot_tests/operations/expected/template/compile/omitFutureValueUnion.res.txt b/snapshot_tests/operations/expected/template/compile/omitFutureValueUnion.res.txt index b607278a..54eb0f1b 100644 --- a/snapshot_tests/operations/expected/template/compile/omitFutureValueUnion.res.txt +++ b/snapshot_tests/operations/expected/template/compile/omitFutureValueUnion.res.txt @@ -1,23 +1,26 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; +var Gql = require("gql").default; var Raw = {}; -var query = (require("gql")` - query { - dogOrHuman { - __typename - ...on Dog { - name - barkVolume - } - ...on Human { - name - } - } - } -`); +var query = Gql`query { +dogOrHuman { +__typename +...on Dog { +name +barkVolume +} + +...on Human { +name +} + +} + +} +`; function parse(value) { var value$1 = value.dogOrHuman; @@ -103,20 +106,22 @@ var Normal = { var Raw$1 = {}; -var query$1 = (require("gql")` - query { - dogOrHuman { - __typename - ...on Dog { - name - barkVolume - } - ...on Human { - name - } - } - } -`); +var query$1 = Gql`query { +dogOrHuman { +__typename +...on Dog { +name +barkVolume +} + +...on Human { +name +} + +} + +} +`; function parse$1(value) { var value$1 = value.dogOrHuman; @@ -199,20 +204,22 @@ var ByConfig = { var Raw$2 = {}; -var query$2 = (require("gql")` - query { - dogOrHuman { - __typename - ...on Dog { - name - barkVolume - } - ...on Human { - name - } - } - } -`); +var query$2 = Gql`query { +dogOrHuman { +__typename +...on Dog { +name +barkVolume +} + +...on Human { +name +} + +} + +} +`; function parse$2(value) { var value$1 = value.dogOrHuman; diff --git a/snapshot_tests/operations/expected/template/compile/pokedexApolloMode.res.txt b/snapshot_tests/operations/expected/template/compile/pokedexApolloMode.res.txt index 5f8a1371..b621ba5f 100644 --- a/snapshot_tests/operations/expected/template/compile/pokedexApolloMode.res.txt +++ b/snapshot_tests/operations/expected/template/compile/pokedexApolloMode.res.txt @@ -1,17 +1,18 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; +var Gql = require("gql").default; var Raw = {}; -var query = (require("gql")` - query { - pokemon(name: "Pikachu") { - id - name - } - } -`); +var query = Gql`query { +pokemon(name: "Pikachu") { +id +name +} + +} +`; function parse(value) { var value$1 = value.pokemon; diff --git a/snapshot_tests/operations/expected/template/compile/pokedexScalars.res.txt b/snapshot_tests/operations/expected/template/compile/pokedexScalars.res.txt index 3618d16a..0fa943ff 100644 --- a/snapshot_tests/operations/expected/template/compile/pokedexScalars.res.txt +++ b/snapshot_tests/operations/expected/template/compile/pokedexScalars.res.txt @@ -1,17 +1,18 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; +var Gql = require("gql").default; var Raw = {}; -var query = (require("gql")` - query pokemon($id: String, $name: String) { - pokemon(name: $name, id: $id) { - id - name - } - } -`); +var query = Gql`query pokemon($id: String, $name: String) { +pokemon(name: $name, id: $id) { +id +name +} + +} +`; function parse(value) { var value$1 = value.pokemon; @@ -84,14 +85,14 @@ var MyQuery = { var Raw$1 = {}; -var query$1 = (require("gql")` - query pokemon($id: String, $name: String) { - pokemon(name: $name, id: $id) { - id - name - } - } -`); +var query$1 = Gql`query pokemon($id: String, $name: String) { +pokemon(name: $name, id: $id) { +id +name +} + +} +`; function parse$1(value) { var value$1 = value.pokemon; diff --git a/snapshot_tests/operations/expected/template/compile/record.res.txt b/snapshot_tests/operations/expected/template/compile/record.res.txt index 03b20994..0e73b68f 100644 --- a/snapshot_tests/operations/expected/template/compile/record.res.txt +++ b/snapshot_tests/operations/expected/template/compile/record.res.txt @@ -1,6 +1,7 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; +var Gql = require("gql").default; function assign_typename(obj, param) { return obj; @@ -12,15 +13,15 @@ var Graphql_ppx_runtime = { var Raw = {}; -var query = (require("gql")` - query { - variousScalars { - __typename - string - int - } - } -`); +var query = Gql`query { +variousScalars { +__typename +string +int +} + +} +`; function parse(value) { var value$1 = value.variousScalars; @@ -72,13 +73,13 @@ var MyQuery = { var Raw$1 = {}; -var query$1 = (require("gql")` - query { - variousScalars { - nullableString - } - } -`); +var query$1 = Gql`query { +variousScalars { +nullableString +} + +} +`; function parse$1(value) { var value$1 = value.variousScalars; @@ -126,14 +127,14 @@ var OneFieldQuery = { var Raw$2 = {}; -var query$2 = (require("gql")` - query { - variousScalars { - __typename - nullableString - } - } -`); +var query$2 = Gql`query { +variousScalars { +__typename +nullableString +} + +} +`; function parse$2(value) { var value$1 = value.variousScalars; @@ -184,12 +185,11 @@ var OneFieldQueryWithTypename = { var Raw$3 = {}; -var query$3 = (require("gql")` - fragment Fragment on VariousScalars { - string - int - } -`); +var query$3 = Gql`fragment Fragment on VariousScalars { +string +int +} +`; function parse$3(value) { return { @@ -226,14 +226,13 @@ var Fragment = { var Raw$4 = {}; -var query$4 = ((frag_0) => require("gql")` - query { - variousScalars { - ...Fragment - } - } - ${frag_0} -`)(query$3); +var query$4 = Gql`query { +variousScalars { +...Fragment +} + +} +${query$3}`; function parse$4(value) { return { @@ -278,18 +277,19 @@ var ExternalFragmentQuery = { var Raw$5 = {}; -var query$5 = (require("gql")` - query { - dogOrHuman { - __typename - ...on Dog { - __typename - name - barkVolume - } - } - } -`); +var query$5 = Gql`query { +dogOrHuman { +__typename +...on Dog { +__typename +name +barkVolume +} + +} + +} +`; function parse$5(value) { var value$1 = value.dogOrHuman; @@ -354,13 +354,12 @@ var InlineFragmentQuery = { var Raw$6 = {}; -var query$6 = (require("gql")` - fragment DogFragment on Dog { - __typename - name - barkVolume - } -`); +var query$6 = Gql`fragment DogFragment on Dog { +__typename +name +barkVolume +} +`; function parse$6(value) { return { @@ -400,17 +399,17 @@ var DogFragment = { var Raw$7 = {}; -var query$7 = ((frag_0) => require("gql")` - query { - dogOrHuman { - __typename - ...on Dog { - ...DogFragment - } - } - } - ${frag_0} -`)(query$6); +var query$7 = Gql`query { +dogOrHuman { +__typename +...on Dog { +...DogFragment +} + +} + +} +${query$6}`; function parse$7(value) { var value$1 = value.dogOrHuman; diff --git a/snapshot_tests/operations/expected/template/compile/recursiveInput.res.txt b/snapshot_tests/operations/expected/template/compile/recursiveInput.res.txt index d3fd6695..86c37132 100644 --- a/snapshot_tests/operations/expected/template/compile/recursiveInput.res.txt +++ b/snapshot_tests/operations/expected/template/compile/recursiveInput.res.txt @@ -1,14 +1,14 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; +var Gql = require("gql").default; var Raw = {}; -var query = (require("gql")` - query ($arg: RecursiveInput!) { - recursiveInput(arg: $arg) - } -`); +var query = Gql`query ($arg: RecursiveInput!) { +recursiveInput(arg: $arg) +} +`; function parse(value) { return { @@ -71,11 +71,10 @@ var MyQuery = { var Raw$1 = {}; -var query$1 = (require("gql")` - query Test($input: problem_input!) { - recursiveRepro(input: $input) - } -`); +var query$1 = Gql`query Test($input: problem_input!) { +recursiveRepro(input: $input) +} +`; function parse$1(value) { return { diff --git a/snapshot_tests/operations/expected/template/compile/scalars.res.txt b/snapshot_tests/operations/expected/template/compile/scalars.res.txt index 6e817bf6..0ed76ff7 100644 --- a/snapshot_tests/operations/expected/template/compile/scalars.res.txt +++ b/snapshot_tests/operations/expected/template/compile/scalars.res.txt @@ -1,25 +1,26 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; +var Gql = require("gql").default; var Raw = {}; -var query = (require("gql")` - query { - variousScalars { - nullableString - string - nullableInt - int - nullableFloat - float - nullableBoolean - boolean - nullableID - id - } - } -`); +var query = Gql`query { +variousScalars { +nullableString +string +nullableInt +int +nullableFloat +float +nullableBoolean +boolean +nullableID +id +} + +} +`; function parse(value) { var value$1 = value.variousScalars; diff --git a/snapshot_tests/operations/expected/template/compile/scalarsArgs.res.txt b/snapshot_tests/operations/expected/template/compile/scalarsArgs.res.txt index 2090ab2a..4216c7c5 100644 --- a/snapshot_tests/operations/expected/template/compile/scalarsArgs.res.txt +++ b/snapshot_tests/operations/expected/template/compile/scalarsArgs.res.txt @@ -1,14 +1,14 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; +var Gql = require("gql").default; var Raw = {}; -var query = (require("gql")` - query ($nullableString: String, $string: String!, $nullableInt: Int, $int: Int!, $nullableFloat: Float, $float: Float!, $nullableBoolean: Boolean, $boolean: Boolean!, $nullableID: ID, $id: ID!) { - scalarsInput(arg: {nullableString: $nullableString, string: $string, nullableInt: $nullableInt, int: $int, nullableFloat: $nullableFloat, float: $float, nullableBoolean: $nullableBoolean, boolean: $boolean, nullableID: $nullableID, id: $id}) - } -`); +var query = Gql`query ($nullableString: String, $string: String!, $nullableInt: Int, $int: Int!, $nullableFloat: Float, $float: Float!, $nullableBoolean: Boolean, $boolean: Boolean!, $nullableID: ID, $id: ID!) { +scalarsInput(arg: {nullableString: $nullableString, string: $string, nullableInt: $nullableInt, int: $int, nullableFloat: $nullableFloat, float: $float, nullableBoolean: $nullableBoolean, boolean: $boolean, nullableID: $nullableID, id: $id}) +} +`; function parse(value) { return { diff --git a/snapshot_tests/operations/expected/template/compile/scalarsInput.res.txt b/snapshot_tests/operations/expected/template/compile/scalarsInput.res.txt index 4c3c8b5f..2d5ddb43 100644 --- a/snapshot_tests/operations/expected/template/compile/scalarsInput.res.txt +++ b/snapshot_tests/operations/expected/template/compile/scalarsInput.res.txt @@ -1,14 +1,14 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; +var Gql = require("gql").default; var Raw = {}; -var query = (require("gql")` - query ($arg: VariousScalarsInput!) { - scalarsInput(arg: $arg) - } -`); +var query = Gql`query ($arg: VariousScalarsInput!) { +scalarsInput(arg: $arg) +} +`; function parse(value) { return { diff --git a/snapshot_tests/operations/expected/template/compile/skipDirectives.res.txt b/snapshot_tests/operations/expected/template/compile/skipDirectives.res.txt index 108fd006..564fae76 100644 --- a/snapshot_tests/operations/expected/template/compile/skipDirectives.res.txt +++ b/snapshot_tests/operations/expected/template/compile/skipDirectives.res.txt @@ -1,21 +1,23 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; +var Gql = require("gql").default; var Raw = {}; -var query = (require("gql")` - query ($var: Boolean!) { - v1: variousScalars { - nullableString @skip(if: $var) - string @skip(if: $var) - } - v2: variousScalars { - nullableString @include(if: $var) - string @include(if: $var) - } - } -`); +var query = Gql`query ($var: Boolean!) { +v1: variousScalars { +nullableString @skip(if: $var) +string @skip(if: $var) +} + +v2: variousScalars { +nullableString @include(if: $var) +string @include(if: $var) +} + +} +`; function parse(value) { var value$1 = value.v1; diff --git a/snapshot_tests/operations/expected/template/compile/subscription.res.txt b/snapshot_tests/operations/expected/template/compile/subscription.res.txt index c6cd8a29..408f01d3 100644 --- a/snapshot_tests/operations/expected/template/compile/subscription.res.txt +++ b/snapshot_tests/operations/expected/template/compile/subscription.res.txt @@ -1,22 +1,25 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; +var Gql = require("gql").default; var Raw = {}; -var query = (require("gql")` - subscription { - simpleSubscription { - __typename - ...on Dog { - name - } - ...on Human { - name - } - } - } -`); +var query = Gql`subscription { +simpleSubscription { +__typename +...on Dog { +name +} + +...on Human { +name +} + +} + +} +`; function parse(value) { var value$1 = value.simpleSubscription; diff --git a/snapshot_tests/operations/expected/template/compile/tagged_template.res.txt b/snapshot_tests/operations/expected/template/compile/tagged_template.res.txt index 641f8b8a..5a6b8259 100644 --- a/snapshot_tests/operations/expected/template/compile/tagged_template.res.txt +++ b/snapshot_tests/operations/expected/template/compile/tagged_template.res.txt @@ -1,6 +1,35 @@ + + Warning number 32 + snapshot_tests/operations/tagged_template.res:6:1-7:70 + + 4 │ } + 5 │ + 6 │ @variadic @taggedTemplate + 7 │ external graphql: (array, array) => string = "graphql" + 8 │ + 9 │ module MyQuery = %graphql( + + unused value graphql. + + + Warning number 32 + snapshot_tests/operations/tagged_template.res:33:1-34:84 + + 31 │ } + 32 │ + 33 │ @variadic @taggedTemplate + 34 │ external graphql: (array, array) => MyTypes.quer + │ y = "graphql" + 35 │ + 36 │ module MyQuery1a = %graphql( + + unused value graphql. + // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; +var Gql = require("gql").default; +var Gatsby = require("gatsby"); var ApolloClient = require("apollo-client"); function deepMerge(json1, param) { @@ -13,22 +42,22 @@ var Graphql_ppx_runtime = { var Raw = {}; -var query = (require("gql")` - query { - variousScalars { - nullableString - string - nullableInt - int - nullableFloat - float - nullableBoolean - boolean - nullableID - id - } - } -`); +var query = Gql`query { +variousScalars { +nullableString +string +nullableInt +int +nullableFloat +float +nullableBoolean +boolean +nullableID +id +} + +} +`; function parse(value) { var value$1 = value.variousScalars; @@ -113,22 +142,22 @@ var MyTypes = {}; var Raw$1 = {}; -var query$1 = (require("gql")` - query { - variousScalars { - nullableString - string - nullableInt - int - nullableFloat - float - nullableBoolean - boolean - nullableID - id - } - } -`); +var query$1 = Gql`query { +variousScalars { +nullableString +string +nullableInt +int +nullableFloat +float +nullableBoolean +boolean +nullableID +id +} + +} +`; function parse$1(value) { var value$1 = value.variousScalars; @@ -211,22 +240,22 @@ var MyQuery1a = { var Raw$2 = {}; -var query$2 = (require("gql")` - query { - variousScalars { - nullableString - string - nullableInt - int - nullableFloat - float - nullableBoolean - boolean - nullableID - id - } - } -`); +var query$2 = Gql`query { +variousScalars { +nullableString +string +nullableInt +int +nullableFloat +float +nullableBoolean +boolean +nullableID +id +} + +} +`; function parse$2(value) { var value$1 = value.variousScalars; @@ -309,22 +338,22 @@ var MyQuery1b = { var Raw$3 = {}; -var query$3 = (require("gatsby").graphql` - query { - variousScalars { - nullableString - string - nullableInt - int - nullableFloat - float - nullableBoolean - boolean - nullableID - id - } - } -`); +var query$3 = Gatsby.graphql`query { +variousScalars { +nullableString +string +nullableInt +int +nullableFloat +float +nullableBoolean +boolean +nullableID +id +} + +} +`; function parse$3(value) { var value$1 = value.variousScalars; @@ -407,22 +436,22 @@ var MyQuery2 = { var Raw$4 = {}; -var query$4 = (require("gatsby").graphql` - query { - variousScalars { - nullableString - string - nullableInt - int - nullableFloat - float - nullableBoolean - boolean - nullableID - id - } - } -`); +var query$4 = Gatsby.graphql`query { +variousScalars { +nullableString +string +nullableInt +int +nullableFloat +float +nullableBoolean +boolean +nullableID +id +} + +} +`; function parse$4(value) { var value$1 = value.variousScalars; @@ -505,22 +534,22 @@ var MyQuery3 = { var Raw$5 = {}; -var query$5 = (require("gatsby")` - query { - variousScalars { - nullableString - string - nullableInt - int - nullableFloat - float - nullableBoolean - boolean - nullableID - id - } - } -`); +var query$5 = Gatsby.graphql`query { +variousScalars { +nullableString +string +nullableInt +int +nullableFloat +float +nullableBoolean +boolean +nullableID +id +} + +} +`; function parse$5(value) { var value$1 = value.variousScalars; @@ -603,12 +632,11 @@ var MyQuery4 = { var Raw$6 = {}; -var query$6 = (require("gatsby")` - fragment ListFragment on Lists { - nullableOfNullable - nullableOfNonNullable - } -`); +var query$6 = Gatsby.graphql`fragment ListFragment on Lists { +nullableOfNullable +nullableOfNonNullable +} +`; function parse$6(value) { var value$1 = value.nullableOfNullable; @@ -664,13 +692,13 @@ var ListFragment = { var Raw$7 = {}; -var query$7 = (require("gatsby")` - query MyQuery5 { - lists { - ...ListFragment - } - } -`); +var query$7 = Gatsby.graphql`query MyQuery5 { +lists { +...ListFragment +} + +} +${query$6}`; function parse$7(value) { return { @@ -710,14 +738,13 @@ var MyQuery5 = { var Raw$8 = {}; -var query$8 = ((frag_0) => require("gatsby")` - query MyQuery6 { - lists { - ...ListFragment - } - } - ${frag_0} -`)(query$6); +var query$8 = Gatsby.graphql`query MyQuery6 { +lists { +...ListFragment +} + +} +${query$6}`; function parse$8(value) { return { @@ -757,13 +784,13 @@ var MyQuery6 = { var Raw$9 = {}; -var query$9 = (require("gql")` - query MyQuery7 { - lists { - ...ListFragment - } - } -`); +var query$9 = Gql`query MyQuery7 { +lists { +...ListFragment +} + +} +${query$6}`; function parse$9(value) { return { diff --git a/snapshot_tests/operations/expected/template/compile/typename.res.txt b/snapshot_tests/operations/expected/template/compile/typename.res.txt index a3426615..c5965b6f 100644 --- a/snapshot_tests/operations/expected/template/compile/typename.res.txt +++ b/snapshot_tests/operations/expected/template/compile/typename.res.txt @@ -1,23 +1,26 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; +var Gql = require("gql").default; var Raw = {}; -var query = (require("gql")` - query { - first: nestedObject { - __typename - inner { - __typename - inner { - __typename - field - } - } - } - } -`); +var query = Gql`query { +first: nestedObject { +__typename +inner { +__typename +inner { +__typename +field +} + +} + +} + +} +`; function parse(value) { var value$1 = value.first; diff --git a/snapshot_tests/operations/expected/template/compile/union.res.txt b/snapshot_tests/operations/expected/template/compile/union.res.txt index 6e35341f..eaa402a3 100644 --- a/snapshot_tests/operations/expected/template/compile/union.res.txt +++ b/snapshot_tests/operations/expected/template/compile/union.res.txt @@ -1,6 +1,7 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; +var Gql = require("gql").default; function assign_typename(obj, param) { return obj; @@ -12,20 +13,22 @@ var Graphql_ppx_runtime = { var Raw = {}; -var query = (require("gql")` - query { - dogOrHuman { - __typename - ...on Dog { - name - barkVolume - } - ...on Human { - name - } - } - } -`); +var query = Gql`query { +dogOrHuman { +__typename +...on Dog { +name +barkVolume +} + +...on Human { +name +} + +} + +} +`; function parse(value) { var value$1 = value.dogOrHuman; @@ -111,20 +114,22 @@ var MyQuery = { var Raw$1 = {}; -var query$1 = (require("gql")` - query { - dogOrHuman { - __typename - ...on Dog { - name - barkVolume - } - ...on Human { - name - } - } - } -`); +var query$1 = Gql`query { +dogOrHuman { +__typename +...on Dog { +name +barkVolume +} + +...on Human { +name +} + +} + +} +`; function parse$1(value) { var value$1 = value.dogOrHuman; @@ -210,21 +215,23 @@ var MyQueryNoError = { var Raw$2 = {}; -var query$2 = (require("gql")` - query { - dogOrHuman { - __typename - ...on Dog { - name - __typename - } - ...on Human { - name - __typename - } - } - } -`); +var query$2 = Gql`query { +dogOrHuman { +__typename +...on Dog { +name +__typename +} + +...on Human { +name +__typename +} + +} + +} +`; function parse$2(value) { var value$1 = value.dogOrHuman; @@ -308,12 +315,11 @@ var NamedQuery = { var Raw$3 = {}; -var query$3 = (require("gql")` - fragment DogFields on Dog { - name - __typename - } -`); +var query$3 = Gql`fragment DogFields on Dog { +name +__typename +} +`; function parse$3(value) { return { @@ -350,17 +356,17 @@ var DogFields = { var Raw$4 = {}; -var query$4 = ((frag_0) => require("gql")` - query dogOrHuman { - dogOrHuman { - __typename - ...on Dog { - ...DogFields - } - } - } - ${frag_0} -`)(query$3); +var query$4 = Gql`query dogOrHuman { +dogOrHuman { +__typename +...on Dog { +...DogFields +} + +} + +} +${query$3}`; function parse$4(value) { var value$1 = value.dogOrHuman; diff --git a/snapshot_tests/operations/expected/template/compile/unionPartial.res.txt b/snapshot_tests/operations/expected/template/compile/unionPartial.res.txt index 630a5747..b27ffb9d 100644 --- a/snapshot_tests/operations/expected/template/compile/unionPartial.res.txt +++ b/snapshot_tests/operations/expected/template/compile/unionPartial.res.txt @@ -1,20 +1,22 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; +var Gql = require("gql").default; var Raw = {}; -var query = (require("gql")` - query { - dogOrHuman { - __typename - ...on Dog { - name - barkVolume - } - } - } -`); +var query = Gql`query { +dogOrHuman { +__typename +...on Dog { +name +barkVolume +} + +} + +} +`; function parse(value) { var value$1 = value.dogOrHuman; diff --git a/snapshot_tests/operations/expected/template/compile/variant.res.txt b/snapshot_tests/operations/expected/template/compile/variant.res.txt index b6fd316f..16cb6eb1 100644 --- a/snapshot_tests/operations/expected/template/compile/variant.res.txt +++ b/snapshot_tests/operations/expected/template/compile/variant.res.txt @@ -1,36 +1,42 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; +var Gql = require("gql").default; var Js_exn = require("rescript/lib/js/js_exn.js"); var Js_json = require("rescript/lib/js/js_json.js"); var Raw = {}; -var query = (require("gql")` - mutation { - mutationForVariant { - baseType - baseTypeList - dog { - name - barkVolume - } - human { - name - } - dogOrHuman { - __typename - ...on Dog { - name - barkVolume - } - ...on Human { - name - } - } - } - } -`); +var query = Gql`mutation { +mutationForVariant { +baseType +baseTypeList +dog { +name +barkVolume +} + +human { +name +} + +dogOrHuman { +__typename +...on Dog { +name +barkVolume +} + +...on Human { +name +} + +} + +} + +} +`; function parse(value) { var value$1 = value.mutationForVariant; diff --git a/snapshot_tests/operations/expected/template/generate/fragmentDefinition.res.txt b/snapshot_tests/operations/expected/template/generate/fragmentDefinition.res.txt index fe2f324b..2f312234 100644 --- a/snapshot_tests/operations/expected/template/generate/fragmentDefinition.res.txt +++ b/snapshot_tests/operations/expected/template/generate/fragmentDefinition.res.txt @@ -522,9 +522,9 @@ l5: lists { ", FragmentWithArgs.query, ), - InlineListFragment.query, + ListFragment.query, ), - ListFragment.query, + InlineListFragment.query, ) let parse = (value): t => { l1: { diff --git a/snapshot_tests/operations/expected/template/generate/tagged_template.res.txt b/snapshot_tests/operations/expected/template/generate/tagged_template.res.txt index b30c035c..6c3dd713 100644 --- a/snapshot_tests/operations/expected/template/generate/tagged_template.res.txt +++ b/snapshot_tests/operations/expected/template/generate/tagged_template.res.txt @@ -2,6 +2,9 @@ module Graphql_ppx_runtime = { // mock let deepMerge = (json1, _) => json1 } + +@variadic @taggedTemplate +external graphql: (array, array) => string = "graphql" module MyQuery: { @@ocaml.warning("-32-30") module Raw: { @@ -78,23 +81,26 @@ function back to the original JSON compatible data ") } type rec t = {variousScalars: t_variousScalars} type rec t_variables = unit - let query = ( - %raw("graphql` - query { - variousScalars { - nullableString - string - nullableInt - int - nullableFloat - float - nullableBoolean - boolean - nullableID - id - } - } -`"): string + let query = graphql( + [ + "query { +variousScalars { +nullableString +string +nullableInt +int +nullableFloat +float +nullableBoolean +boolean +nullableID +id +} + +} +", + ], + [], ) let parse = (value): t => { variousScalars: { @@ -248,6 +254,9 @@ function back to the original JSON compatible data ") module MyTypes = { type query } + +@variadic @taggedTemplate +external graphql: (array, array) => MyTypes.query = "graphql" module MyQuery1a: { @@ocaml.warning("-32-30") module Raw: { @@ -324,23 +333,26 @@ function back to the original JSON compatible data ") } type rec t = {variousScalars: t_variousScalars} type rec t_variables = unit - let query = ( - %raw("graphql` - query { - variousScalars { - nullableString - string - nullableInt - int - nullableFloat - float - nullableBoolean - boolean - nullableID - id - } - } -`"): MyTypes.query + let query = graphql( + [ + "query { +variousScalars { +nullableString +string +nullableInt +int +nullableFloat +float +nullableBoolean +boolean +nullableID +id +} + +} +", + ], + [], ) let parse = (value): t => { variousScalars: { @@ -490,6 +502,9 @@ function back to the original JSON compatible data ") external toJson: Raw.t => Js.Json.t = "%identity" external variablesToJson: Raw.t_variables => Js.Json.t = "%identity" } + +@variadic @taggedTemplate +external graphql: (array, array) => string = "graphql" module MyQuery1b: { @@ocaml.warning("-32-30") module Raw: { @@ -566,23 +581,26 @@ function back to the original JSON compatible data ") } type rec t = {variousScalars: t_variousScalars} type rec t_variables = unit - let query = ( - %raw("graphql` - query { - variousScalars { - nullableString - string - nullableInt - int - nullableFloat - float - nullableBoolean - boolean - nullableID - id - } - } -`"): string + let query = graphql( + [ + "query { +variousScalars { +nullableString +string +nullableInt +int +nullableFloat +float +nullableBoolean +boolean +nullableID +id +} + +} +", + ], + [], ) let parse = (value): t => { variousScalars: { @@ -808,23 +826,29 @@ function back to the original JSON compatible data ") } type rec t = {variousScalars: t_variousScalars} type rec t_variables = unit - let query = ( - %raw("require("gatsby").graphql` - query { - variousScalars { - nullableString - string - nullableInt - int - nullableFloat - float - nullableBoolean - boolean - nullableID - id - } - } -`"): string + @module("gatsby") @taggedTemplate + external graphql: (array, array) => string = "graphql" + external graphql_allow_string: string => string = "%identity" + let query = graphql( + [ + "query { +variousScalars { +nullableString +string +nullableInt +int +nullableFloat +float +nullableBoolean +boolean +nullableID +id +} + +} +", + ], + [], ) let parse = (value): t => { variousScalars: { @@ -1050,23 +1074,29 @@ function back to the original JSON compatible data ") } type rec t = {variousScalars: t_variousScalars} type rec t_variables = unit - let query = ( - %raw("require("gatsby").graphql` - query { - variousScalars { - nullableString - string - nullableInt - int - nullableFloat - float - nullableBoolean - boolean - nullableID - id - } - } -`"): string + @module("gatsby") @taggedTemplate + external graphql: (array, array) => string = "graphql" + external graphql_allow_string: string => string = "%identity" + let query = graphql( + [ + "query { +variousScalars { +nullableString +string +nullableInt +int +nullableFloat +float +nullableBoolean +boolean +nullableID +id +} + +} +", + ], + [], ) let parse = (value): t => { variousScalars: { @@ -1292,23 +1322,29 @@ function back to the original JSON compatible data ") } type rec t = {variousScalars: t_variousScalars} type rec t_variables = unit - let query = ( - %raw("require("gatsby")` - query { - variousScalars { - nullableString - string - nullableInt - int - nullableFloat - float - nullableBoolean - boolean - nullableID - id - } - } -`"): string + @module("gatsby") @taggedTemplate + external graphql: (array, array) => string = "graphql" + external graphql_allow_string: string => string = "%identity" + let query = graphql( + [ + "query { +variousScalars { +nullableString +string +nullableInt +int +nullableFloat +float +nullableBoolean +boolean +nullableID +id +} + +} +", + ], + [], ) let parse = (value): t => { variousScalars: { @@ -1496,13 +1532,18 @@ function back to the original JSON-compatible data ") nullableOfNonNullable: option>, } type t_Lists = t - let query = ( - %raw("require("gatsby")` - fragment ListFragment on Lists { - nullableOfNullable - nullableOfNonNullable - } -`"): string + @module("gatsby") @taggedTemplate + external graphql: (array, array) => string = "graphql" + external graphql_allow_string: string => string = "%identity" + let query = graphql( + [ + "fragment ListFragment on Lists { +nullableOfNullable +nullableOfNonNullable +} +", + ], + [], ) let parse = ( (value): t => { @@ -1593,14 +1634,21 @@ function back to the original JSON compatible data ") } type rec t = {lists: ListFragment.t_Lists} type rec t_variables = unit - let query = ( - %raw("require("gatsby")` - query MyQuery5 { - lists { - ...ListFragment - } - } -`"): string + @module("gatsby") @taggedTemplate + external graphql: (array, array) => string = "graphql" + external graphql_allow_string: string => string = "%identity" + let query = graphql( + [ + "query MyQuery5 { +lists { +...ListFragment +} + +} +", + "", + ], + [ListFragment.query], ) let parse = (value): t => { lists: { @@ -1651,15 +1699,21 @@ function back to the original JSON compatible data ") } type rec t = {lists: ListFragment.t_Lists} type rec t_variables = unit - let query = ( - %raw("(frag_0) => require("gatsby")` - query MyQuery6 { - lists { - ...ListFragment - } - } - ${frag_0} -`")(ListFragment.query): string + @module("gatsby") @taggedTemplate + external graphql: (array, array) => string = "graphql" + external graphql_allow_string: string => string = "%identity" + let query = graphql( + [ + "query MyQuery6 { +lists { +...ListFragment +} + +} +", + "", + ], + [ListFragment.query], ) let parse = (value): t => { lists: { @@ -1710,14 +1764,18 @@ function back to the original JSON compatible data ") } type rec t = {lists: ListFragment.t_Lists} type rec t_variables = unit - let query = ( - %raw("graphql` - query MyQuery7 { - lists { - ...ListFragment - } - } -`"): string + let query = graphql( + [ + "query MyQuery7 { +lists { +...ListFragment +} + +} +", + "", + ], + [ListFragment.query], ) let parse = (value): t => { lists: { @@ -1778,14 +1836,17 @@ function back to the original JSON-compatible data ") nullableOfNonNullable: option>, } type t_Lists = t - @module("apollo-client") external graphql: array => int = "gql" - let query = graphql([ - "fragment ListFragment8 on Lists { + @module("apollo-client") @variadic external gql: (array, array) => int = "gql" + let query = gql( + [ + "fragment ListFragment8 on Lists { nullableOfNullable nullableOfNonNullable } ", - ]) + ], + [], + ) let parse = ( (value): t => { nullableOfNullable: { @@ -1932,8 +1993,8 @@ function back to the original JSON compatible data ") variousScalars: t_variousScalars, } type rec t_variables = unit - @module("apollo-client") external graphql: (array, int) => int = "gql" - let query = graphql( + @module("apollo-client") @variadic external gql: (array, array) => int = "gql" + let query = gql( [ "query MyQuery8 { lists { @@ -1957,7 +2018,7 @@ id ", "", ], - ListFragment8.query, + [ListFragment8.query], ) let parse = (value): t => { lists: { diff --git a/snapshot_tests/operations/expected/uncurried/compile/fragmentDefinition.res.txt b/snapshot_tests/operations/expected/uncurried/compile/fragmentDefinition.res.txt index f7736a07..b2f73389 100644 --- a/snapshot_tests/operations/expected/uncurried/compile/fragmentDefinition.res.txt +++ b/snapshot_tests/operations/expected/uncurried/compile/fragmentDefinition.res.txt @@ -263,7 +263,7 @@ var Wrapper = { var Raw$5 = {}; -var query$3 = "query MyQuery($arg1: String) {\nl1: lists {\n...ListFragment \n}\n\nl2: lists {\n...ListFragment \n...ListFragment \n}\n\nl3: lists {\nnullableOfNullable \n...ListFragment \n...ListFragment \n}\n\nl4: lists {\nnullableOfNullable \n...InlineListFragment \n}\n\nl5: lists {\n...FragmentWithArgs \n}\n\n}\nfragment FragmentWithArgs on Lists {\nlistWithArg(arg1: $arg1) \n}\nfragment InlineListFragment on Lists {\nnullableOfNullable \nnullableOfNonNullable \n}\nfragment ListFragment on Lists {\nnullableOfNullable \nnullableOfNonNullable \n}\n"; +var query$3 = "query MyQuery($arg1: String) {\nl1: lists {\n...ListFragment \n}\n\nl2: lists {\n...ListFragment \n...ListFragment \n}\n\nl3: lists {\nnullableOfNullable \n...ListFragment \n...ListFragment \n}\n\nl4: lists {\nnullableOfNullable \n...InlineListFragment \n}\n\nl5: lists {\n...FragmentWithArgs \n}\n\n}\nfragment FragmentWithArgs on Lists {\nlistWithArg(arg1: $arg1) \n}\nfragment ListFragment on Lists {\nnullableOfNullable \nnullableOfNonNullable \n}\nfragment InlineListFragment on Lists {\nnullableOfNullable \nnullableOfNonNullable \n}\n"; function parse$5(value) { var value$1 = value.l2; diff --git a/snapshot_tests/operations/expected/uncurried/compile/tagged_template.res.txt b/snapshot_tests/operations/expected/uncurried/compile/tagged_template.res.txt index 29c0ab02..d557048b 100644 --- a/snapshot_tests/operations/expected/uncurried/compile/tagged_template.res.txt +++ b/snapshot_tests/operations/expected/uncurried/compile/tagged_template.res.txt @@ -1,6 +1,7 @@ // Generated by ReScript, PLEASE EDIT WITH CARE 'use strict'; +var Gatsby = require("gatsby"); var ApolloClient = require("apollo-client"); function deepMerge(json1, param) { @@ -13,22 +14,22 @@ var Graphql_ppx_runtime = { var Raw = {}; -var query = (graphql` - query { - variousScalars { - nullableString - string - nullableInt - int - nullableFloat - float - nullableBoolean - boolean - nullableID - id - } - } -`); +var query = graphql`query { +variousScalars { +nullableString +string +nullableInt +int +nullableFloat +float +nullableBoolean +boolean +nullableID +id +} + +} +`; function parse(value) { var value$1 = value.variousScalars; @@ -113,22 +114,22 @@ var MyTypes = {}; var Raw$1 = {}; -var query$1 = (graphql` - query { - variousScalars { - nullableString - string - nullableInt - int - nullableFloat - float - nullableBoolean - boolean - nullableID - id - } - } -`); +var query$1 = graphql`query { +variousScalars { +nullableString +string +nullableInt +int +nullableFloat +float +nullableBoolean +boolean +nullableID +id +} + +} +`; function parse$1(value) { var value$1 = value.variousScalars; @@ -211,22 +212,22 @@ var MyQuery1a = { var Raw$2 = {}; -var query$2 = (graphql` - query { - variousScalars { - nullableString - string - nullableInt - int - nullableFloat - float - nullableBoolean - boolean - nullableID - id - } - } -`); +var query$2 = graphql`query { +variousScalars { +nullableString +string +nullableInt +int +nullableFloat +float +nullableBoolean +boolean +nullableID +id +} + +} +`; function parse$2(value) { var value$1 = value.variousScalars; @@ -309,22 +310,22 @@ var MyQuery1b = { var Raw$3 = {}; -var query$3 = (require("gatsby").graphql` - query { - variousScalars { - nullableString - string - nullableInt - int - nullableFloat - float - nullableBoolean - boolean - nullableID - id - } - } -`); +var query$3 = Gatsby.graphql`query { +variousScalars { +nullableString +string +nullableInt +int +nullableFloat +float +nullableBoolean +boolean +nullableID +id +} + +} +`; function parse$3(value) { var value$1 = value.variousScalars; @@ -407,22 +408,22 @@ var MyQuery2 = { var Raw$4 = {}; -var query$4 = (require("gatsby").graphql` - query { - variousScalars { - nullableString - string - nullableInt - int - nullableFloat - float - nullableBoolean - boolean - nullableID - id - } - } -`); +var query$4 = Gatsby.graphql`query { +variousScalars { +nullableString +string +nullableInt +int +nullableFloat +float +nullableBoolean +boolean +nullableID +id +} + +} +`; function parse$4(value) { var value$1 = value.variousScalars; @@ -505,22 +506,22 @@ var MyQuery3 = { var Raw$5 = {}; -var query$5 = (require("gatsby")` - query { - variousScalars { - nullableString - string - nullableInt - int - nullableFloat - float - nullableBoolean - boolean - nullableID - id - } - } -`); +var query$5 = Gatsby.graphql`query { +variousScalars { +nullableString +string +nullableInt +int +nullableFloat +float +nullableBoolean +boolean +nullableID +id +} + +} +`; function parse$5(value) { var value$1 = value.variousScalars; @@ -603,12 +604,11 @@ var MyQuery4 = { var Raw$6 = {}; -var query$6 = (require("gatsby")` - fragment ListFragment on Lists { - nullableOfNullable - nullableOfNonNullable - } -`); +var query$6 = Gatsby.graphql`fragment ListFragment on Lists { +nullableOfNullable +nullableOfNonNullable +} +`; function parse$6(value) { var value$1 = value.nullableOfNullable; @@ -664,13 +664,13 @@ var ListFragment = { var Raw$7 = {}; -var query$7 = (require("gatsby")` - query MyQuery5 { - lists { - ...ListFragment - } - } -`); +var query$7 = Gatsby.graphql`query MyQuery5 { +lists { +...ListFragment +} + +} +${query$6}`; function parse$7(value) { return { @@ -710,14 +710,13 @@ var MyQuery5 = { var Raw$8 = {}; -var query$8 = ((frag_0) => require("gatsby")` - query MyQuery6 { - lists { - ...ListFragment - } - } - ${frag_0} -`)(query$6); +var query$8 = Gatsby.graphql`query MyQuery6 { +lists { +...ListFragment +} + +} +${query$6}`; function parse$8(value) { return { @@ -757,13 +756,13 @@ var MyQuery6 = { var Raw$9 = {}; -var query$9 = (graphql` - query MyQuery7 { - lists { - ...ListFragment - } - } -`); +var query$9 = graphql`query MyQuery7 { +lists { +...ListFragment +} + +} +${query$6}`; function parse$9(value) { return { diff --git a/snapshot_tests/operations/expected/uncurried/generate/fragmentDefinition.res.txt b/snapshot_tests/operations/expected/uncurried/generate/fragmentDefinition.res.txt index fe2f324b..2f312234 100644 --- a/snapshot_tests/operations/expected/uncurried/generate/fragmentDefinition.res.txt +++ b/snapshot_tests/operations/expected/uncurried/generate/fragmentDefinition.res.txt @@ -522,9 +522,9 @@ l5: lists { ", FragmentWithArgs.query, ), - InlineListFragment.query, + ListFragment.query, ), - ListFragment.query, + InlineListFragment.query, ) let parse = (value): t => { l1: { diff --git a/snapshot_tests/operations/expected/uncurried/generate/tagged_template.res.txt b/snapshot_tests/operations/expected/uncurried/generate/tagged_template.res.txt index b30c035c..6c3dd713 100644 --- a/snapshot_tests/operations/expected/uncurried/generate/tagged_template.res.txt +++ b/snapshot_tests/operations/expected/uncurried/generate/tagged_template.res.txt @@ -2,6 +2,9 @@ module Graphql_ppx_runtime = { // mock let deepMerge = (json1, _) => json1 } + +@variadic @taggedTemplate +external graphql: (array, array) => string = "graphql" module MyQuery: { @@ocaml.warning("-32-30") module Raw: { @@ -78,23 +81,26 @@ function back to the original JSON compatible data ") } type rec t = {variousScalars: t_variousScalars} type rec t_variables = unit - let query = ( - %raw("graphql` - query { - variousScalars { - nullableString - string - nullableInt - int - nullableFloat - float - nullableBoolean - boolean - nullableID - id - } - } -`"): string + let query = graphql( + [ + "query { +variousScalars { +nullableString +string +nullableInt +int +nullableFloat +float +nullableBoolean +boolean +nullableID +id +} + +} +", + ], + [], ) let parse = (value): t => { variousScalars: { @@ -248,6 +254,9 @@ function back to the original JSON compatible data ") module MyTypes = { type query } + +@variadic @taggedTemplate +external graphql: (array, array) => MyTypes.query = "graphql" module MyQuery1a: { @@ocaml.warning("-32-30") module Raw: { @@ -324,23 +333,26 @@ function back to the original JSON compatible data ") } type rec t = {variousScalars: t_variousScalars} type rec t_variables = unit - let query = ( - %raw("graphql` - query { - variousScalars { - nullableString - string - nullableInt - int - nullableFloat - float - nullableBoolean - boolean - nullableID - id - } - } -`"): MyTypes.query + let query = graphql( + [ + "query { +variousScalars { +nullableString +string +nullableInt +int +nullableFloat +float +nullableBoolean +boolean +nullableID +id +} + +} +", + ], + [], ) let parse = (value): t => { variousScalars: { @@ -490,6 +502,9 @@ function back to the original JSON compatible data ") external toJson: Raw.t => Js.Json.t = "%identity" external variablesToJson: Raw.t_variables => Js.Json.t = "%identity" } + +@variadic @taggedTemplate +external graphql: (array, array) => string = "graphql" module MyQuery1b: { @@ocaml.warning("-32-30") module Raw: { @@ -566,23 +581,26 @@ function back to the original JSON compatible data ") } type rec t = {variousScalars: t_variousScalars} type rec t_variables = unit - let query = ( - %raw("graphql` - query { - variousScalars { - nullableString - string - nullableInt - int - nullableFloat - float - nullableBoolean - boolean - nullableID - id - } - } -`"): string + let query = graphql( + [ + "query { +variousScalars { +nullableString +string +nullableInt +int +nullableFloat +float +nullableBoolean +boolean +nullableID +id +} + +} +", + ], + [], ) let parse = (value): t => { variousScalars: { @@ -808,23 +826,29 @@ function back to the original JSON compatible data ") } type rec t = {variousScalars: t_variousScalars} type rec t_variables = unit - let query = ( - %raw("require("gatsby").graphql` - query { - variousScalars { - nullableString - string - nullableInt - int - nullableFloat - float - nullableBoolean - boolean - nullableID - id - } - } -`"): string + @module("gatsby") @taggedTemplate + external graphql: (array, array) => string = "graphql" + external graphql_allow_string: string => string = "%identity" + let query = graphql( + [ + "query { +variousScalars { +nullableString +string +nullableInt +int +nullableFloat +float +nullableBoolean +boolean +nullableID +id +} + +} +", + ], + [], ) let parse = (value): t => { variousScalars: { @@ -1050,23 +1074,29 @@ function back to the original JSON compatible data ") } type rec t = {variousScalars: t_variousScalars} type rec t_variables = unit - let query = ( - %raw("require("gatsby").graphql` - query { - variousScalars { - nullableString - string - nullableInt - int - nullableFloat - float - nullableBoolean - boolean - nullableID - id - } - } -`"): string + @module("gatsby") @taggedTemplate + external graphql: (array, array) => string = "graphql" + external graphql_allow_string: string => string = "%identity" + let query = graphql( + [ + "query { +variousScalars { +nullableString +string +nullableInt +int +nullableFloat +float +nullableBoolean +boolean +nullableID +id +} + +} +", + ], + [], ) let parse = (value): t => { variousScalars: { @@ -1292,23 +1322,29 @@ function back to the original JSON compatible data ") } type rec t = {variousScalars: t_variousScalars} type rec t_variables = unit - let query = ( - %raw("require("gatsby")` - query { - variousScalars { - nullableString - string - nullableInt - int - nullableFloat - float - nullableBoolean - boolean - nullableID - id - } - } -`"): string + @module("gatsby") @taggedTemplate + external graphql: (array, array) => string = "graphql" + external graphql_allow_string: string => string = "%identity" + let query = graphql( + [ + "query { +variousScalars { +nullableString +string +nullableInt +int +nullableFloat +float +nullableBoolean +boolean +nullableID +id +} + +} +", + ], + [], ) let parse = (value): t => { variousScalars: { @@ -1496,13 +1532,18 @@ function back to the original JSON-compatible data ") nullableOfNonNullable: option>, } type t_Lists = t - let query = ( - %raw("require("gatsby")` - fragment ListFragment on Lists { - nullableOfNullable - nullableOfNonNullable - } -`"): string + @module("gatsby") @taggedTemplate + external graphql: (array, array) => string = "graphql" + external graphql_allow_string: string => string = "%identity" + let query = graphql( + [ + "fragment ListFragment on Lists { +nullableOfNullable +nullableOfNonNullable +} +", + ], + [], ) let parse = ( (value): t => { @@ -1593,14 +1634,21 @@ function back to the original JSON compatible data ") } type rec t = {lists: ListFragment.t_Lists} type rec t_variables = unit - let query = ( - %raw("require("gatsby")` - query MyQuery5 { - lists { - ...ListFragment - } - } -`"): string + @module("gatsby") @taggedTemplate + external graphql: (array, array) => string = "graphql" + external graphql_allow_string: string => string = "%identity" + let query = graphql( + [ + "query MyQuery5 { +lists { +...ListFragment +} + +} +", + "", + ], + [ListFragment.query], ) let parse = (value): t => { lists: { @@ -1651,15 +1699,21 @@ function back to the original JSON compatible data ") } type rec t = {lists: ListFragment.t_Lists} type rec t_variables = unit - let query = ( - %raw("(frag_0) => require("gatsby")` - query MyQuery6 { - lists { - ...ListFragment - } - } - ${frag_0} -`")(ListFragment.query): string + @module("gatsby") @taggedTemplate + external graphql: (array, array) => string = "graphql" + external graphql_allow_string: string => string = "%identity" + let query = graphql( + [ + "query MyQuery6 { +lists { +...ListFragment +} + +} +", + "", + ], + [ListFragment.query], ) let parse = (value): t => { lists: { @@ -1710,14 +1764,18 @@ function back to the original JSON compatible data ") } type rec t = {lists: ListFragment.t_Lists} type rec t_variables = unit - let query = ( - %raw("graphql` - query MyQuery7 { - lists { - ...ListFragment - } - } -`"): string + let query = graphql( + [ + "query MyQuery7 { +lists { +...ListFragment +} + +} +", + "", + ], + [ListFragment.query], ) let parse = (value): t => { lists: { @@ -1778,14 +1836,17 @@ function back to the original JSON-compatible data ") nullableOfNonNullable: option>, } type t_Lists = t - @module("apollo-client") external graphql: array => int = "gql" - let query = graphql([ - "fragment ListFragment8 on Lists { + @module("apollo-client") @variadic external gql: (array, array) => int = "gql" + let query = gql( + [ + "fragment ListFragment8 on Lists { nullableOfNullable nullableOfNonNullable } ", - ]) + ], + [], + ) let parse = ( (value): t => { nullableOfNullable: { @@ -1932,8 +1993,8 @@ function back to the original JSON compatible data ") variousScalars: t_variousScalars, } type rec t_variables = unit - @module("apollo-client") external graphql: (array, int) => int = "gql" - let query = graphql( + @module("apollo-client") @variadic external gql: (array, array) => int = "gql" + let query = gql( [ "query MyQuery8 { lists { @@ -1957,7 +2018,7 @@ id ", "", ], - ListFragment8.query, + [ListFragment8.query], ) let parse = (value): t => { lists: { diff --git a/snapshot_tests/operations/tagged_template.res b/snapshot_tests/operations/tagged_template.res index f8a3f9a9..cb682ac2 100644 --- a/snapshot_tests/operations/tagged_template.res +++ b/snapshot_tests/operations/tagged_template.res @@ -3,6 +3,9 @@ module Graphql_ppx_runtime = { let deepMerge = (json1, _) => json1 } +@variadic @taggedTemplate +external graphql: (array, array) => string = "graphql" + module MyQuery = %graphql( ` { @@ -27,6 +30,9 @@ module MyTypes = { type query } +@variadic @taggedTemplate +external graphql: (array, array) => MyTypes.query = "graphql" + module MyQuery1a = %graphql( ` { @@ -47,6 +53,9 @@ module MyQuery1a = %graphql( {templateTag: "graphql", templateTagReturnType: "MyTypes.query"} ) +@variadic @taggedTemplate +external graphql: (array, array) => string = "graphql" + module MyQuery1b = %graphql( ` { @@ -128,7 +137,7 @@ module MyQuery4 = %graphql( } } ` - {templateTag: graphql, templateTagLocation: "gatsby"} + {templateTagImport: "graphql", templateTagLocation: "gatsby"} ) %graphql( @@ -144,7 +153,7 @@ module MyQuery4 = %graphql( } ` { - templateTag: graphql, + templateTagImport: "graphql", templateTagLocation: "gatsby", fragmentInQuery: "exclude", } @@ -159,7 +168,7 @@ module MyQuery4 = %graphql( } ` { - templateTag: graphql, + templateTagImport: "graphql", templateTagLocation: "gatsby", fragmentInQuery: "include", } diff --git a/src/graphql_compiler/graphql_ast.ml b/src/graphql_compiler/graphql_ast.ml index f4c83f0b..6eb644db 100644 --- a/src/graphql_compiler/graphql_ast.ml +++ b/src/graphql_compiler/graphql_ast.ml @@ -79,6 +79,10 @@ type definition = type document = definition list +let get_spanning_of_definition = function + | Operation op -> op.span + | Fragment frag -> frag.span + let rec innermost_name = function | Tr_named { item; _ } | Tr_non_null_named { item; _ } -> item | Tr_list { item; _ } | Tr_non_null_list { item; _ } -> innermost_name item diff --git a/src/graphql_compiler/graphql_printer.ml b/src/graphql_compiler/graphql_printer.ml index 9f451ec0..f13d7f8f 100644 --- a/src/graphql_compiler/graphql_printer.ml +++ b/src/graphql_compiler/graphql_printer.ml @@ -6,8 +6,8 @@ exception Cant_find_fragment_type of string spanning type t = | String of string - | FragmentNameRef of string - | FragmentQueryRef of string + | FragmentNameRef of { contents : string spanning; allow_string : bool } + | FragmentQueryRef of { contents : string spanning; allow_string : bool } let rec type_ref_name = function | Named n -> n @@ -73,7 +73,15 @@ let print_directives ds = let print_fragment_spread s = [| String "..."; - FragmentNameRef s.fs_name.item; + FragmentNameRef + { + contents = s.fs_name; + allow_string = + s.fs_directives + |> List.exists (fun x -> + if x.item.d_name.item = "ppxAllowStringReturnType" then true + else false); + }; String (" " ^ print_directives s.fs_directives); |] @@ -234,17 +242,17 @@ let print_definition schema def = | Operation { item = operation; _ } -> print_operation schema operation | Fragment { item = fragment; _ } -> print_fragment schema fragment -module StringSet = Set.Make (String) - let find_fragment_refs parts = parts |> Array.fold_left (fun acc -> function | String _ -> acc - | FragmentNameRef r -> StringSet.add r acc + | FragmentNameRef r -> + Hashtbl.replace acc r.contents.item (r.contents, r.allow_string); + acc | FragmentQueryRef _ -> acc) - StringSet.empty - |> StringSet.elements + (Hashtbl.create ~random:false 10) + |> Hashtbl.to_seq_values |> List.of_seq let compress_parts (parts : t array) = parts |> Array.to_list @@ -263,6 +271,7 @@ let print_document schema defs = [ parts; fragment_refs |> Array.of_list - |> Array.map (fun ref -> FragmentQueryRef ref); + |> Array.map (fun ref -> + FragmentQueryRef { contents = fst ref; allow_string = snd ref }); ] |> compress_parts diff --git a/src/graphql_compiler/graphql_printer.mli b/src/graphql_compiler/graphql_printer.mli index ae0b4b25..16b99d5a 100644 --- a/src/graphql_compiler/graphql_printer.mli +++ b/src/graphql_compiler/graphql_printer.mli @@ -2,8 +2,14 @@ exception Cant_find_fragment_type of string Source_pos.spanning type t = | String of string - | FragmentNameRef of string - | FragmentQueryRef of string + | FragmentNameRef of { + contents : string Source_pos.spanning; + allow_string : bool; + } + | FragmentQueryRef of { + contents : string Source_pos.spanning; + allow_string : bool; + } val type_ref_name : Schema.type_ref -> string val print_type : Graphql_ast.type_ref -> string diff --git a/src/graphql_compiler/source_pos.ml b/src/graphql_compiler/source_pos.ml index 0316f77e..3d8bbd1b 100644 --- a/src/graphql_compiler/source_pos.ml +++ b/src/graphql_compiler/source_pos.ml @@ -19,6 +19,7 @@ let replace span item = { span = span.span; item } let map f span = { span = span.span; item = f span.item } let start_pos span = fst span.span let end_pos span = snd span.span +let span span = span.item type ast_position = { pos_fname : string; diff --git a/src/ppx/output_module.ml b/src/ppx/output_module.ml index 05907d5b..36f377a2 100644 --- a/src/ppx/output_module.ml +++ b/src/ppx/output_module.ml @@ -27,8 +27,8 @@ module VariableFinderImpl = struct let from_self (self : t) : StringSet.t = !self end -let constraint_on_type exp type_name = - Ast_helper.Exp.constraint_ exp +let constraint_on_type ?loc exp type_name = + Ast_helper.Exp.constraint_ ?loc exp (base_type_name (match type_name with None -> "string" | Some type_name -> type_name)) @@ -77,8 +77,8 @@ let compress_parts (parts : Graphql_printer.t array) = [] |> List.rev |> Array.of_list -let make_fragment_query f = - Ast_helper.Exp.ident +let make_fragment_query ?loc f = + Ast_helper.Exp.ident ?loc { Location.txt = Longident.parse (f ^ ".query"); loc = Location.none } let emit_printed_template_query (parts : Graphql_printer.t array) config = @@ -91,7 +91,7 @@ let emit_printed_template_query (parts : Graphql_printer.t array) config = (fun acc -> function | String _ -> acc | FragmentNameRef _ -> acc - | FragmentQueryRef f -> f :: acc) + | FragmentQueryRef f -> f.contents :: acc) [] |> List.rev | Exclude -> [] @@ -100,7 +100,7 @@ let emit_printed_template_query (parts : Graphql_printer.t array) config = Array.fold_left (fun acc -> function | String s -> acc ^ s - | FragmentNameRef f -> acc ^ f + | FragmentNameRef f -> acc ^ f.contents.item | FragmentQueryRef _ -> acc) "" parts in @@ -112,7 +112,7 @@ let emit_printed_template_query (parts : Graphql_printer.t array) config = in query :: fragments |> List.fold_left (fun acc el -> acc ^ el) "" -let emit_printed_query parts config = +let emit_printed_query ~config parts = let open Graphql_printer in let make_string s = Ast_helper.Exp.constant (Parsetree.Pconst_string (s, Location.none, None)) @@ -128,19 +128,23 @@ let emit_printed_query parts config = Array.fold_left (fun acc -> function | String s -> acc ^ s - | FragmentNameRef f -> acc ^ f + | FragmentNameRef f -> acc ^ f.contents.item | FragmentQueryRef _ -> acc) "" parts in let fragment_query_refs = match config.fragment_in_query with - | Include -> + | Ppx_config.Include -> parts |> Array.fold_left (fun acc -> function | String _ -> acc | FragmentNameRef _ -> acc - | FragmentQueryRef f -> make_fragment_query f :: acc) + | FragmentQueryRef f -> + make_fragment_query + ~loc:(config.map_loc f.contents.span |> Output_utils.conv_loc) + f.contents.item + :: acc) [] |> List.rev | Exclude -> [] @@ -191,7 +195,7 @@ let rec emit_json config = function Js.Json.number [%e Ast_helper.Exp.constant (Pconst_float (string_of_int i, None))]] | `StringExpr parts -> - add_uapp [%expr Js.Json.string [%e emit_printed_query parts config]] + add_uapp [%expr Js.Json.string [%e emit_printed_query ~config parts]] let wrap_template_tag ?import ?location ?template_tag source = match (import, location, template_tag) with @@ -239,67 +243,95 @@ let make_printed_query config document = Ast_serializer_apollo.serialize_document source document |> emit_json config | Ppx_config.String -> ( match (config.template_tag_is_function, config.template_tag) with - | Some true, (_, location, _) when location <> None -> + | Some true, (template_tag, location, _import) + when location <> None || template_tag <> None -> let source_list = source |> Array.to_list in - add_uapp - @@ Ast_helper.Exp.apply - (Ast_helper.Exp.ident - { Location.txt = Longident.Lident "graphql"; loc = Location.none }) - (( Nolabel, - Ast_helper.Exp.array - (emit_printed_query - (source_list - |> List.filter (function - | Graphql_printer.FragmentQueryRef _ -> false - | _ -> true) - |> Array.of_list) - config - :: (source_list - |> filter_map (function - | Graphql_printer.FragmentQueryRef _ -> Some [%expr ""] - | _ -> None))) ) - :: (source_list + Ast_helper.Exp.apply + (Ast_helper.Exp.ident + { + Location.txt = + Longident.Lident (template_tag |> Option.get_or_else "graphql"); + loc = Location.none; + }) + [ + ( Nolabel, + Ast_helper.Exp.array + (emit_printed_query ~config + (source_list + |> List.filter (function + | Graphql_printer.FragmentQueryRef _ -> false + | _ -> true) + |> Array.of_list) + :: (source_list + |> filter_map (function + | Graphql_printer.FragmentQueryRef _ -> Some [%expr ""] + | _ -> None))) ); + ( Nolabel, + Ast_helper.Exp.array + (source_list |> filter_map (function | Graphql_printer.FragmentQueryRef x -> - Some (Nolabel, make_fragment_query x) - | _ -> None))) - | _, (template_tag, location, import) - when template_tag <> None || location <> None -> - let open Graphql_printer in - let fragments = - source - |> Array.fold_left - (fun acc -> function - | String _ -> acc - | FragmentNameRef _ -> acc - | FragmentQueryRef f -> f :: acc) - [] - |> List.rev - in - let template_tag = - wrap_template_tag ?template_tag ?location ?import - (pretty_print (emit_printed_template_query source config)) - in - constraint_on_type - (match (config.fragment_in_query, fragments) with - | Exclude, _ | _, [] -> wrap_raw template_tag - | Include, fragments -> - let fragment_names = - fragments |> List.mapi (fun i _frag -> "frag_" ^ string_of_int i) - in - let frag_fun = - "(" - ^ (List.tl fragment_names - |> List.fold_left - (fun acc el -> acc ^ ", " ^ el) - (List.hd fragment_names)) - ^ ") => " - in - Ast_helper.Exp.apply - (wrap_raw (frag_fun ^ template_tag)) - (fragments |> List.map (fun f -> (Nolabel, make_fragment_query f)))) - config.template_tag_return_type - | _ -> emit_printed_query source config) + Some (make_fragment_query x.contents.item) + | _ -> None)) ); + ] + | template_tag_is_function, (template_tag, location, _import) + when (location <> None || template_tag <> None) + && template_tag_is_function <> Some true -> + let source_list = source |> Array.to_list in + Ast_helper.Exp.apply + (Ast_helper.Exp.ident + { + Location.txt = + Longident.Lident (template_tag |> Option.get_or_else "graphql"); + loc = Location.none; + }) + [ + ( Nolabel, + Ast_helper.Exp.array + (emit_printed_query ~config + (source_list + |> List.filter (function + | Graphql_printer.FragmentQueryRef _ -> false + | _ -> true) + |> Array.of_list) + :: (source_list + |> filter_map (function + | Graphql_printer.FragmentQueryRef _ -> Some [%expr ""] + | _ -> None))) ); + ( Nolabel, + Ast_helper.Exp.array + (source_list + |> filter_map (function + | Graphql_printer.FragmentQueryRef x -> + let fragment_query = + make_fragment_query + ~loc: + (config.map_loc x.contents.span + |> Output_utils.conv_loc) + x.contents.item + in + if x.allow_string then + (* this coerces the value from a string to the desired return type *) + Some + (Ast_helper.Exp.apply + (Ast_helper.Exp.ident + { + Location.txt = + Longident.Lident "graphql_allow_string"; + loc = Location.none; + }) + [ + ( Nolabel, + constraint_on_type + ~loc: + (config.map_loc x.contents.span + |> Output_utils.conv_loc) + fragment_query (Some "string") ); + ]) + else Some fragment_query + | _ -> None)) ); + ] + | _ -> emit_printed_query ~config source) let signature_module name signature = { @@ -445,8 +477,8 @@ let wrap_query_module ~loc:module_loc ~module_type definition name contents [ wrap_module ~module_type ~loc:module_loc name contents ] | None, None -> contents -let wrap_query_module_signature ~signature definition name config = - let loc = Location.none in +let wrap_query_module_signature ~signature ?(loc = Location.none) definition + name config = let module_name = match name with Some name -> name ^ "_inner" | None -> "Inner" in @@ -583,13 +615,14 @@ let rec create_arity_fn arity typ = | 0 -> typ | arity -> Ast_helper.Typ.arrow Nolabel typ (create_arity_fn (arity - 1) typ) -let graphql_external (config : output_config) document = +let graphql_external (config : output_config) _ = match config with | { - template_tag = import, Some location, _; + template_tag = template_tag, location, import; template_tag_return_type; template_tag_is_function = Some true; - } -> + } + when location <> None -> let return_type = match template_tag_return_type with | None -> "string" @@ -598,28 +631,85 @@ let graphql_external (config : output_config) document = let import = match import with None -> "default" | Some import -> import in - let arity = - Graphql_printer.print_document config.schema document - |> Array.fold_left - (fun arity el -> - match el with - | Graphql_printer.FragmentQueryRef _ -> arity + 1 - | _ -> arity) - 0 + [ + Ast_helper.Str.primitive + (Ast_helper.Val.mk + ~attrs: + (match location with + | None -> [] + | Some location -> + [ + Ast_helper.Attr.mk + { txt = "module"; loc = Location.none } + (PStr [ Ast_helper.Str.eval (const_str_expr location) ]); + Ast_helper.Attr.mk + { txt = "variadic"; loc = Location.none } + (PStr []); + ]) + ~prim:[ import ] + { + txt = template_tag |> Option.get_or_else "graphql"; + loc = Location.none; + } + (Ast_helper.Typ.arrow Nolabel [%type: string array] + (Ast_helper.Typ.arrow Nolabel + (base_type ~inner:[ base_type_name return_type ] "array") + (base_type_name return_type)))); + ] + | { template_tag = template_tag, location, import; template_tag_return_type } + when location <> None -> + let return_type = + match template_tag_return_type with + | None -> "string" + | Some return_type -> return_type + in + let import = + match (import, location, template_tag) with + | None, Some _, _ -> "default" + | Some import, Some _, _ -> import + | _, None, Some template_tag -> template_tag + | _, None, None -> assert false in [ Ast_helper.Str.primitive (Ast_helper.Val.mk ~attrs: - [ - Ast_helper.Attr.mk - { txt = "bs.module"; loc = Location.none } - (PStr [ Ast_helper.Str.eval (const_str_expr location) ]); - ] + (match location with + | None -> + [ + Ast_helper.Attr.mk + { txt = "taggedTemplate"; loc = Location.none } + (PStr []); + ] + | Some location -> + [ + Ast_helper.Attr.mk + { txt = "module"; loc = Location.none } + (PStr [ Ast_helper.Str.eval (const_str_expr location) ]); + Ast_helper.Attr.mk + { txt = "taggedTemplate"; loc = Location.none } + (PStr []); + ]) ~prim:[ import ] - { txt = "graphql"; loc = Location.none } + { + txt = template_tag |> Option.get_or_else "graphql"; + loc = Location.none; + } (Ast_helper.Typ.arrow Nolabel [%type: string array] - (create_arity_fn arity (base_type_name return_type)))); + (Ast_helper.Typ.arrow Nolabel + (base_type ~inner:[ base_type_name return_type ] "array") + (base_type_name return_type)))); + (* + this converts a string to the expected return type to make old fragments + compatible if you use apollo with fragments that don't use the template tag + this use-case is useful if you have two different GraphQL clients and you want + to mix the fragments while they are not using the template tag + *) + Ast_helper.Str.primitive + (Ast_helper.Val.mk ~attrs:[] ~prim:[ "%identity" ] + { txt = "graphql_allow_string"; loc = Location.none } + (Ast_helper.Typ.arrow Nolabel [%type: string] + (base_type_name return_type))); ] | _ -> [] diff --git a/src/ppx/output_types.ml b/src/ppx/output_types.ml index b4ed8670..d7b00bee 100644 --- a/src/ppx/output_types.ml +++ b/src/ppx/output_types.ml @@ -18,14 +18,6 @@ let make_error_raiser message = let const_str_expr s = Ast_helper.Exp.constant (Pconst_string (s, loc, None)) -let base_type ?(inner = []) ?loc name = - Ast_helper.Typ.constr - { - Location.txt = Longident.parse name; - loc = (match loc with None -> Location.none | Some loc -> loc); - } - inner - let rec generate_type ?atLoc ~config ~path ~raw = function | Res_string _ -> base_type ?loc:atLoc "string" | Res_nullable { inner } -> diff --git a/src/ppx/output_utils.ml b/src/ppx/output_utils.ml index ff60a8ac..1194dede 100644 --- a/src/ppx/output_utils.ml +++ b/src/ppx/output_utils.ml @@ -18,6 +18,14 @@ let extend_loc_from_start (loc : Location.t) cnum = let base_type_name ?(loc = Location.none) name = Ast_helper.Typ.constr { txt = Longident.parse name; loc } [] +let base_type ?(inner = []) ?loc name = + Ast_helper.Typ.constr + { + Location.txt = Longident.parse name; + loc = (match loc with None -> Location.none | Some loc -> loc); + } + inner + let const_str_expr s = Ast_helper.Exp.constant (Pconst_string (s, Location.none, None)) diff --git a/tests_native/record.ml b/tests_native/record.ml index f71db51e..f4e7b886 100644 --- a/tests_native/record.ml +++ b/tests_native/record.ml @@ -26,7 +26,10 @@ module MyQuery = type qt = MyQuery.t -module MyQueryTest = struct +module MyQueryTest : sig + val pp : Format.formatter -> qt -> unit + val equal : qt -> qt -> bool +end = struct let pp fmt (obj : qt) = pp_record fmt [ ("variousScalars", (pp_to_print Scalars.pp) obj.variousScalars) ]