Skip to content

Commit

Permalink
✨ - Tagged template literal support
Browse files Browse the repository at this point in the history
  • Loading branch information
jfrolich committed May 15, 2024
1 parent 13ee3ac commit e23fc30
Show file tree
Hide file tree
Showing 89 changed files with 4,111 additions and 2,113 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

We've found a bug for you!
snapshot_tests/operations/errors/fragmentTemplateTagNotFound.res:11:3-15:3

9 │
10 │ %graphql(`
11 │ query MyQuery @ppxConfig(templateTag: "gql", templateTagReturnType: "
│ bool") {
12 │  lists {
13 │  ...ListFragment
14 │  }
15 │  }
16 │ `)
17 │

The value gql can't be found

Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

We've found a bug for you!
snapshot_tests/operations/errors/fragmentTemplateTagWrongType.res:11:10-21

9 │ query MyQuery @ppxConfig(templateTagLocation: "gql", templateTagRetur
│ nType: "bool") {
10 │ lists {
11 │ ...ListFragment
12 │ }
13 │ }
14 │ `)

This array item has type: string
But this array is expected to have items of type: bool

Arrays can only contain items of the same type.

Possible solutions:
- Convert all values in the array to the same type.
- Use a tuple, if your array is of fixed length. Tuples can mix types freely, and compiles to a JavaScript array. Example of a tuple: `let myTuple = (10, "hello", 15.5, true)

Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

We've found a bug for you!
snapshot_tests/operations/errors/fragmentTemplateTagWrongTypeOnFragment.res:11:8-24

9 │ fragment ListFragment on Lists @ppxConfig(templateTagLocation: "gql"
│ , templateTagReturnType: "bool") {
10 │ nullableOfNullable
11 │ ...ListFragmentInner
12 │ }
13 │ `)
14 │

This array item has type: string
But this array is expected to have items of type: bool

Arrays can only contain items of the same type.

Possible solutions:
- Convert all values in the array to the same type.
- Use a tuple, if your array is of fixed length. Tuples can mix types freely, and compiles to a JavaScript array. Example of a tuple: `let myTuple = (10, "hello", 15.5, true)

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

We've found a bug for you!
snapshot_tests/operations/errors/fragmentTemplateTagWrongTypeOnFragmentReverse.res:11:8-24

9 │ fragment ListFragment on Lists {
10 │ nullableOfNullable
11 │ ...ListFragmentInner
12 │ }
13 │ `)
14 │

This has type: bool
But this function argument is expecting: string

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

We've found a bug for you!
snapshot_tests/operations/errors/fragmentTemplateTagWrongTypeReverse.res:11:10-21

9 │ query MyQuery {
10 │ lists {
11 │ ...ListFragment
12 │ }
13 │ }
14 │ `)

This has type: bool
But this function argument is expecting: string

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

We've found a bug for you!
snapshot_tests/operations/errors/fragmentTemplateTagWrongTypes.res:19:10-26

17 │ lists {
18 │ ...ListFragment
19 │ ...ListFragmentWrong
20 │ }
21 │ }
22 │ `)

This array item has type: string
But this array is expected to have items of type: bool

Arrays can only contain items of the same type.

Possible solutions:
- Convert all values in the array to the same type.
- Use a tuple, if your array is of fixed length. Tuples can mix types freely, and compiles to a JavaScript array. Example of a tuple: `let myTuple = (10, "hello", 15.5, true)

16 changes: 16 additions & 0 deletions snapshot_tests/operations/errors/fragmentTemplateTagNotFound.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
%graphql(`
fragment ListFragment on Lists {
nullableOfNullable
nullableOfNonNullable
}
`)

module WrongFragmentName = ListFragment

%graphql(`
query MyQuery @ppxConfig(templateTag: "gql", templateTagReturnType: "bool") {
lists {
...ListFragment
}
}
`)
14 changes: 14 additions & 0 deletions snapshot_tests/operations/errors/fragmentTemplateTagWrongType.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
%graphql(`
fragment ListFragment on Lists {
nullableOfNullable
nullableOfNonNullable
}
`)

%graphql(`
query MyQuery @ppxConfig(templateTagLocation: "gql", templateTagReturnType: "bool") {
lists {
...ListFragment
}
}
`)
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
%graphql(`
fragment ListFragmentInner on Lists {
nullableOfNullable
nullableOfNonNullable
}
`)

%graphql(`
fragment ListFragment on Lists @ppxConfig(templateTagLocation: "gql", templateTagReturnType: "bool") {
nullableOfNullable
...ListFragmentInner
}
`)
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
%graphql(`
fragment ListFragmentInner on Lists @ppxConfig(templateTagLocation: "gql", templateTagReturnType: "bool") {
nullableOfNullable
nullableOfNonNullable
}
`)

%graphql(`
fragment ListFragment on Lists {
nullableOfNullable
...ListFragmentInner
}
`)
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
%graphql(`
fragment ListFragment on Lists @ppxConfig(templateTagLocation: "gql", templateTagReturnType: "bool") {
nullableOfNullable
nullableOfNonNullable
}
`)

%graphql(`
query MyQuery {
lists {
...ListFragment
}
}
`)
22 changes: 22 additions & 0 deletions snapshot_tests/operations/errors/fragmentTemplateTagWrongTypes.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
%graphql(`
fragment ListFragment on Lists @ppxConfig(templateTagLocation: "gql", templateTagReturnType: "bool") {
nullableOfNullable
nullableOfNonNullable
}
`)

%graphql(`
fragment ListFragmentWrong on Lists {
nullableOfNullable
nullableOfNonNullable
}
`)

%graphql(`
query MyQuery @ppxConfig(templateTagLocation: "gql", templateTagReturnType: "bool") {
lists {
...ListFragment
...ListFragmentWrong
}
}
`)
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
// Generated by ReScript, PLEASE EDIT WITH CARE
'use strict';

var Gql = require("gql").default;

var Raw = {};

var query = "fragment ListFragment on Lists {\n__typename \nnullableOfNullable \nnullableOfNonNullable \n}\n";

function parse(value) {
var value$1 = value.nullableOfNullable;
var value$2 = value.nullableOfNonNullable;
return {
__typename: value.__typename,
nullableOfNullable: !(value$1 == null) ? value$1.map(function (value) {
if (!(value == null)) {
return value;
}

}) : undefined,
nullableOfNonNullable: !(value$2 == null) ? value$2.map(function (value) {
return value;
}) : undefined
};
}

function serialize(value) {
var value$1 = value.nullableOfNonNullable;
var nullableOfNonNullable = value$1 !== undefined ? value$1.map(function (value) {
return value;
}) : null;
var value$2 = value.nullableOfNullable;
var nullableOfNullable = value$2 !== undefined ? value$2.map(function (value) {
if (value !== undefined) {
return value;
} else {
return null;
}
}) : null;
var value$3 = value.__typename;
return {
__typename: value$3,
nullableOfNullable: nullableOfNullable,
nullableOfNonNullable: nullableOfNonNullable
};
}

function verifyArgsAndParse(_ListFragment, value) {
return parse(value);
}

function verifyName(param) {

}

var ListFragment = {
Raw: Raw,
query: query,
parse: parse,
serialize: serialize,
verifyArgsAndParse: verifyArgsAndParse,
verifyName: verifyName
};

var Raw$1 = {};

var query$1 = Gql`query MyQuery {
lists {
...ListFragment @ppxAllowStringReturnType
}

}
${query}`;

function parse$1(value) {
return {
lists: parse(value.lists)
};
}

function serialize$1(value) {
var value$1 = value.lists;
var lists = serialize(value$1);
return {
lists: lists
};
}

function serializeVariables(param) {

}

function makeVariables(param) {

}

function makeDefaultVariables(param) {

}

var MyQuery = {
Raw: Raw$1,
query: query$1,
parse: parse$1,
serialize: serialize$1,
serializeVariables: serializeVariables,
makeVariables: makeVariables,
makeDefaultVariables: makeDefaultVariables
};

exports.ListFragment = ListFragment;
exports.MyQuery = MyQuery;
/* query Not a pure module */
Loading

0 comments on commit e23fc30

Please sign in to comment.