forked from Gusto/apollo-federation-ruby
-
Notifications
You must be signed in to change notification settings - Fork 0
/
accounts.rb
62 lines (49 loc) · 1.05 KB
/
accounts.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# frozen_string_literal: true
require_relative './graphql_server'
# extend type Query {
# me: User
# }
# type User @key(fields: "id") {
# id: ID!
# name: String
# username: String
# }
USERS = [
{
id: '1',
name: 'Ada Lovelace',
birthDate: '1815-12-10',
username: '@ada',
},
{
id: '2',
name: 'Alan Turing',
birthDate: '1912-06-23',
username: '@complete',
},
].freeze
class User < BaseObject
key fields: :id
field :id, ID, null: false
field :name, String, null: true
field :username, String, null: true
def self.resolve_reference(object, _context)
USERS.find { |user| user[:id] == object[:id] }
end
end
class Query < BaseObject
field :me, User, null: true
def me
USERS[0]
end
end
class AccountSchema < GraphQL::Schema
if Gem::Version.new(GraphQL::VERSION) < Gem::Version.new('1.12.0')
use GraphQL::Execution::Interpreter
use GraphQL::Analysis::AST
end
use ApolloFederation::Tracing
include ApolloFederation::Schema
query(Query)
end
GraphQLServer.run(AccountSchema, Port: 5001)