From 72a3eced685428a3ee07c869b093f50f0578d242 Mon Sep 17 00:00:00 2001 From: Peter Morgenstern Date: Thu, 11 Jan 2024 09:16:37 +0100 Subject: [PATCH] Add test for array in response variables --- spec/example_schema/types/objects/user.rb | 1 + spec/example_schema/types/query.rb | 1 + spec/example_schema/types/query_b.rb | 2 +- spec/graphql/queries/response_variables.graphql | 1 + spec/graphql/queries/response_variables.json | 3 ++- spec/graphql/queries/response_variables_spec.rb | 4 ++-- 6 files changed, 8 insertions(+), 4 deletions(-) diff --git a/spec/example_schema/types/objects/user.rb b/spec/example_schema/types/objects/user.rb index 9724e9c..8b987a1 100644 --- a/spec/example_schema/types/objects/user.rb +++ b/spec/example_schema/types/objects/user.rb @@ -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 diff --git a/spec/example_schema/types/query.rb b/spec/example_schema/types/query.rb index c1cbc99..542e8da 100644 --- a/spec/example_schema/types/query.rb +++ b/spec/example_schema/types/query.rb @@ -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 diff --git a/spec/example_schema/types/query_b.rb b/spec/example_schema/types/query_b.rb index c59b742..5619892 100644 --- a/spec/example_schema/types/query_b.rb +++ b/spec/example_schema/types/query_b.rb @@ -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 diff --git a/spec/graphql/queries/response_variables.graphql b/spec/graphql/queries/response_variables.graphql index cb9dae4..4c69e65 100644 --- a/spec/graphql/queries/response_variables.graphql +++ b/spec/graphql/queries/response_variables.graphql @@ -2,5 +2,6 @@ query { currentUser { id name + roles } } diff --git a/spec/graphql/queries/response_variables.json b/spec/graphql/queries/response_variables.json index 008ac3c..030e10e 100644 --- a/spec/graphql/queries/response_variables.json +++ b/spec/graphql/queries/response_variables.json @@ -2,7 +2,8 @@ { "currentUser": { "id": "1", - "name": "{{user_name}}" + "name": "{{user_name}}", + "roles": "{{user_roles}}" } } ] diff --git a/spec/graphql/queries/response_variables_spec.rb b/spec/graphql/queries/response_variables_spec.rb index e8bf5c4..d755a0a 100644 --- a/spec/graphql/queries/response_variables_spec.rb +++ b/spec/graphql/queries/response_variables_spec.rb @@ -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