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]
|
||||
context = {
|
||||
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)
|
||||
render(json: result)
|
||||
|
||||
@@ -4,14 +4,9 @@ module Types
|
||||
include GraphQL::Types::Relay::HasNodeField
|
||||
include GraphQL::Types::Relay::HasNodesField
|
||||
|
||||
# TODO: remove me
|
||||
field :test_field, [String], null: false,
|
||||
description: "An example field added by the generator"
|
||||
def test_field
|
||||
[
|
||||
SecureRandom.uuid,
|
||||
SecureRandom.uuid,
|
||||
]
|
||||
field :current_user, UserType, null: true
|
||||
def current_user
|
||||
context[:current_user]
|
||||
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 {
|
||||
"""
|
||||
An example field added by the generator
|
||||
"""
|
||||
testField: [String!]!
|
||||
currentUser: User
|
||||
}
|
||||
|
||||
type User {
|
||||
email: String!
|
||||
firstName: String!
|
||||
fullName: String!
|
||||
id: ID!
|
||||
lastName: String!
|
||||
}
|
||||
|
||||
input UserAttributesInput {
|
||||
|
||||
@@ -8,8 +8,8 @@ module Auth
|
||||
@email = attributes[:email]
|
||||
end
|
||||
|
||||
def customer
|
||||
@customer ||= Customer.find_by(email: email, auth_id: id)
|
||||
def user
|
||||
@user ||= User.find_by(email: email)
|
||||
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