Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .ocamlformat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
profile = conventional
1 change: 1 addition & 0 deletions dune-project
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
(lang dune 1.1)
(using menhir 2.0)
(using fmt 1.2)
12 changes: 6 additions & 6 deletions graphql/test/schema_test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ let suite = [
])
);
("fragments cannot form cycles", `Quick, fun () ->
let query = "
let query = {|
fragment F1 on Foo {
... on Bar {
baz {
Expand All @@ -143,7 +143,7 @@ let suite = [
{
... F1
}
" in
|} in
test_query query (`Assoc [
"errors", `List [
`Assoc [
Expand All @@ -153,7 +153,7 @@ let suite = [
])
);
("fragments combine nested fields", `Quick, fun () ->
let query = "
let query = {|
query Q {
users {
role
Expand All @@ -165,7 +165,7 @@ let suite = [
name
}
}
" in
|} in
test_query query (`Assoc [
"data", `Assoc [
"users", `List [
Expand All @@ -186,7 +186,7 @@ let suite = [
])
);
("introspection query should be accepted", `Quick, fun () ->
let query = "
let query = {|
query IntrospectionQuery {
__schema {
queryType { name }
Expand Down Expand Up @@ -278,7 +278,7 @@ let suite = [
}
}
}
" in
|} in
match Graphql_parser.parse query with
| Error err -> failwith err
| Ok doc ->
Expand Down
41 changes: 23 additions & 18 deletions graphql_parser/test/parser_test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ let test_query query =
Alcotest.failf "Failed to parse %s: %s" query err

let test_introspection_query () =
test_query
"query IntrospectionQuery {
test_query {|
query IntrospectionQuery {
__schema {
queryType { name }
mutationType { name }
Expand Down Expand Up @@ -90,11 +90,12 @@ let test_introspection_query () =
}
}
}
}"
}
|}

let test_kitchen_sink () =
test_query
"query queryName($foo: ComplexType, $site: Site = MOBILE) {
test_query {|
query queryName($foo: ComplexType, $site: Site = MOBILE) {
whoever123is: node(id: [123, 456]) {
id ,
... on User @defer {
Expand Down Expand Up @@ -137,17 +138,18 @@ let test_kitchen_sink () =
}

fragment frag on Friend {
foo(size: $size, bar: $b, obj: {key: \"value\"})
foo(size: $size, bar: $b, obj: {key: "value"})
}

{
unnamed(truthy: true, falsey: false, nullish: null),
query
}"
}
|}

let test_variables () =
test_query
"query Named($a: String, $b: Float) {
test_query {|
query Named($a: String, $b: Float) {
x
}

Expand All @@ -157,22 +159,24 @@ let test_variables () =

query NonNull($a: ID!, $b: [Foo]!, $c: [Foo!], $d: [Foo!]!) {
x
}"
}
|}

let test_default_values () =
test_query
"query DefaultValues(
test_query {|
query DefaultValues(
$a: Int = 1,
$b: [String] = [\"a\"],
$b: [String] = ["a"],
$c: Obj = {x: {y: true}, z: RED},
$d: [Obj]! = [{x: {y: null}, z: BLUE}]
) {
x
}"
}
|}

let test_keywords () =
test_query
"query Keywords(
test_query {|
query Keywords(
$fragment: Int,
$false: Int,
$mutation: Int,
Expand Down Expand Up @@ -218,11 +222,12 @@ let test_keywords () =

fragment true on Foo {
a
}"
}
|}

let test_escaped_string () =
test_query {|
{
{
escaped_quote(x: "\"")
backslash(x: "\\")
slash(x: "/")
Expand Down