Skip to content

Commit

Permalink
Merge pull request #110 from peterfication/add-response-variables-arr…
Browse files Browse the repository at this point in the history
…ay-test

Add test for array in response variables
  • Loading branch information
peterfication committed Jan 11, 2024
2 parents 41e2b85 + 4851bfa commit 5b14af0
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 4 deletions.
1 change: 1 addition & 0 deletions graphql/test-schema-b.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ type User {
name: String!
nameFromContext: String
nameFromVariables: String
roles: [String!]!
}
24 changes: 24 additions & 0 deletions graphql/test-schema-b.json
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,30 @@
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "roles",
"description": null,
"args": [],
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "LIST",
"name": null,
"ofType": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "String",
"ofType": null
}
}
}
},
"isDeprecated": false,
"deprecationReason": null
}
],
"inputFields": null,
Expand Down
1 change: 1 addition & 0 deletions graphql/test-schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ type User {
name: String!
nameFromContext: String
nameFromVariables: String
roles: [String!]!
}
24 changes: 24 additions & 0 deletions graphql/test-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,30 @@
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "roles",
"description": null,
"args": [],
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "LIST",
"name": null,
"ofType": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "String",
"ofType": null
}
}
}
},
"isDeprecated": false,
"deprecationReason": null
}
],
"inputFields": null,
Expand Down
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 5b14af0

Please sign in to comment.