Merge pull request #4 from exstake/feature/add-current-user-query
add currentUser query
This commit is contained in:
@@ -10,7 +10,7 @@ class GraphqlController < ApplicationController
|
|||||||
operation_name = params[:operationName]
|
operation_name = params[:operationName]
|
||||||
context = {
|
context = {
|
||||||
current_auth: current_auth,
|
current_auth: current_auth,
|
||||||
current_user: current_admin_user, # || current_auth.current_user,
|
current_user: current_auth&.user,
|
||||||
}
|
}
|
||||||
result = XStakeSchema.execute(query, variables: variables, context: context, operation_name: operation_name)
|
result = XStakeSchema.execute(query, variables: variables, context: context, operation_name: operation_name)
|
||||||
render(json: result)
|
render(json: result)
|
||||||
|
|||||||
@@ -4,14 +4,9 @@ module Types
|
|||||||
include GraphQL::Types::Relay::HasNodeField
|
include GraphQL::Types::Relay::HasNodeField
|
||||||
include GraphQL::Types::Relay::HasNodesField
|
include GraphQL::Types::Relay::HasNodesField
|
||||||
|
|
||||||
# TODO: remove me
|
field :current_user, UserType, null: true
|
||||||
field :test_field, [String], null: false,
|
def current_user
|
||||||
description: "An example field added by the generator"
|
context[:current_user]
|
||||||
def test_field
|
|
||||||
[
|
|
||||||
SecureRandom.uuid,
|
|
||||||
SecureRandom.uuid,
|
|
||||||
]
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
14
app/graphql/types/user_type.rb
Normal file
14
app/graphql/types/user_type.rb
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
module Types
|
||||||
|
class UserType < Types::BaseObject
|
||||||
|
# implements GraphQL::Types::Relay::Node
|
||||||
|
|
||||||
|
global_id_field :id
|
||||||
|
|
||||||
|
field :id, ID, null: false
|
||||||
|
field :first_name, String, null: false
|
||||||
|
field :last_name, String, null: false
|
||||||
|
field :full_name, String, null: false
|
||||||
|
field :email, String, null: false
|
||||||
|
end
|
||||||
|
end
|
||||||
13
app/javascript/__generated__/schema.graphql
generated
13
app/javascript/__generated__/schema.graphql
generated
@@ -35,10 +35,15 @@ type Mutation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Query {
|
type Query {
|
||||||
"""
|
currentUser: User
|
||||||
An example field added by the generator
|
}
|
||||||
"""
|
|
||||||
testField: [String!]!
|
type User {
|
||||||
|
email: String!
|
||||||
|
firstName: String!
|
||||||
|
fullName: String!
|
||||||
|
id: ID!
|
||||||
|
lastName: String!
|
||||||
}
|
}
|
||||||
|
|
||||||
input UserAttributesInput {
|
input UserAttributesInput {
|
||||||
|
|||||||
@@ -8,8 +8,8 @@ module Auth
|
|||||||
@email = attributes[:email]
|
@email = attributes[:email]
|
||||||
end
|
end
|
||||||
|
|
||||||
def customer
|
def user
|
||||||
@customer ||= Customer.find_by(email: email, auth_id: id)
|
@user ||= User.find_by(email: email)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
14
spec/graphql/types/user_type_spec.rb
Normal file
14
spec/graphql/types/user_type_spec.rb
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
require "rails_helper"
|
||||||
|
|
||||||
|
RSpec.describe(Types::UserType) do
|
||||||
|
subject { described_class }
|
||||||
|
|
||||||
|
describe "arguments" do
|
||||||
|
it { is_expected.to(have_a_field(:id).of_type("ID!")) }
|
||||||
|
it { is_expected.to(have_a_field(:first_name).of_type("String!")) }
|
||||||
|
it { is_expected.to(have_a_field(:last_name).of_type("String!")) }
|
||||||
|
it { is_expected.to(have_a_field(:full_name).of_type("String!")) }
|
||||||
|
it { is_expected.to(have_a_field(:email).of_type("String!")) }
|
||||||
|
end
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user