Skip to content

Commit

Permalink
Add test for array in response variables
Browse files Browse the repository at this point in the history
  • Loading branch information
peterfication committed Jan 11, 2024
1 parent 41e2b85 commit 72a3ece
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 4 deletions.
1 change: 1 addition & 0 deletions spec/example_schema/types/objects/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class User < GraphQL::Schema::Object
field :name, String, null: false
field :name_from_context, String, null: true
field :name_from_variables, String, null: true
field :roles, [String], null: false
end
end
end
1 change: 1 addition & 0 deletions spec/example_schema/types/query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def current_user(**args)
name: "John Doe",
name_from_variables: args[:user_name],
name_from_context: context[:user_name],
roles: %w[],
}
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/example_schema/types/query_b.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module Types
class QueryB < GraphQL::Schema::Object
field(:other_user, Types::Objects::User, null: false)
def other_user
{ id: 1, name: "John Doe" }
{ id: 1, name: "John Doe", roles: [] }
end
end
end
1 change: 1 addition & 0 deletions spec/graphql/queries/response_variables.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ query {
currentUser {
id
name
roles
}
}
3 changes: 2 additions & 1 deletion spec/graphql/queries/response_variables.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
{
"currentUser": {
"id": "1",
"name": "{{user_name}}"
"name": "{{user_name}}",
"roles": "{{user_roles}}"
}
}
]
4 changes: 2 additions & 2 deletions spec/graphql/queries/response_variables_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
# of a database object during the loading of the response file.
allow(User).to receive(:first).and_return(user)

{ user_name: "Maria Doe" }
{ user_name: "Maria Doe", user_roles: %w[admin user] }
end
let(:user) { { id: 1, name: "Maria Doe" } }
let(:user) { { id: 1, name: "Maria Doe", roles: %w[admin user] } }

it { is_expected.to match_graphql_response }
end
Expand Down

0 comments on commit 72a3ece

Please sign in to comment.