馃寠 A GraphQL implementation in Gleam
1/// Snapshot tests for mutation parsing
2import birdie
3import gleam/string
4import gleeunit
5import swell/parser
6
7pub fn main() {
8 gleeunit.main()
9}
10
11// Helper to format AST as string for snapshots
12fn format_ast(doc: parser.Document) -> String {
13 string.inspect(doc)
14}
15
16pub fn parse_simple_anonymous_mutation_test() {
17 let query = "mutation { createUser(name: \"Alice\") { id name } }"
18
19 let doc = case parser.parse(query) {
20 Ok(d) -> d
21 Error(_) -> panic as "Parse failed"
22 }
23
24 birdie.snap(title: "Simple anonymous mutation", content: format_ast(doc))
25}
26
27pub fn parse_named_mutation_test() {
28 let query = "mutation CreateUser { createUser(name: \"Alice\") { id name } }"
29
30 let doc = case parser.parse(query) {
31 Ok(d) -> d
32 Error(_) -> panic as "Parse failed"
33 }
34
35 birdie.snap(title: "Named mutation", content: format_ast(doc))
36}
37
38pub fn parse_mutation_with_input_object_test() {
39 let query =
40 "
41 mutation {
42 createUser(input: { name: \"Alice\", email: \"alice@example.com\", age: 30 }) {
43 id
44 name
45 email
46 }
47 }
48 "
49
50 let doc = case parser.parse(query) {
51 Ok(d) -> d
52 Error(_) -> panic as "Parse failed"
53 }
54
55 birdie.snap(
56 title: "Parse mutation with input object argument",
57 content: format_ast(doc),
58 )
59}
60
61pub fn parse_multiple_mutations_test() {
62 let query =
63 "
64 mutation {
65 createUser(name: \"Alice\") { id }
66 deleteUser(id: \"123\") { success }
67 }
68 "
69
70 let doc = case parser.parse(query) {
71 Ok(d) -> d
72 Error(_) -> panic as "Parse failed"
73 }
74
75 birdie.snap(
76 title: "Multiple mutations in one operation",
77 content: format_ast(doc),
78 )
79}
80
81pub fn parse_mutation_with_nested_selections_test() {
82 let query =
83 "
84 mutation {
85 createPost(input: { title: \"Hello\" }) {
86 id
87 author {
88 id
89 name
90 }
91 tags
92 }
93 }
94 "
95
96 let doc = case parser.parse(query) {
97 Ok(d) -> d
98 Error(_) -> panic as "Parse failed"
99 }
100
101 birdie.snap(
102 title: "Mutation with nested selections",
103 content: format_ast(doc),
104 )
105}