-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspec.graphqls
More file actions
114 lines (95 loc) · 2.3 KB
/
Copy pathspec.graphqls
File metadata and controls
114 lines (95 loc) · 2.3 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# begin of Hypermedia GraphQL definition
"""
The ResourceIdentifier directive must be applied to all the field definitions which are required to identify a resource.
"""
directive @ResourceIdentifier on FIELD_DEFINITION
scalar _ResourceInput
"""
Resource must be implemented by all types which are being used as resources.
All identifiers must be marked using the @ResourceIdentifier directive.
"""
interface Resource {
actions: [_Action]
}
extend type Mutation {
_action(subjects: [_ResourceInput!]! objects: [_ResourceInput!] action: _Action!):_Resource
}
extend type Query {
_resource(subject: _ResourceInput!):_Resource
}
# end of Hypermedia GraphQL definition
#
# beginning of Hypermedia GraphQL implementation
"""
All Resources must be added to the _Resource union.
"""
union _Resource = Cart | Item
"""
All possible actions must be added to the _Action enum
"""
enum _Action {
checkout
addToCart
removeFromCart
}
# end of Hypermedia GraphQL implementation
type Cart implements Resource {
id: ID! @ResourceIdentifier
items: [Item]
actions: [_Action]
}
type Item implements Resource {
id: ID! @ResourceIdentifier
name: String
actions: [_Action]
}
type Query {
cart(id: ID!): Cart
item(id: ID!): Item
}
type Mutation {
}
query GetItem($id: ID!){
item(id: $id){
id
name
actions
}
}
query GetCart($id: ID!) {
cart(id: $id){
id
items {
id
name
}
actions
}
}
mutation AddItemToCart ($item: _ResourceInput! $cart: _ResourceInput!) {
_action(action: addToCart,subjects: [$item], objects: [$cart]){
... on Cart {
id
}
}
}
# variables: {"item":{"__typename":"Item","id":1},"cart":{"__typename":"Cart","id":1}}
mutation RemoveItemFromCart ($item: _ResourceInput! $cart: _ResourceInput!) {
_action(action: removeFromCart,subjects: [$item], objects: [$cart]){
... on Cart {
id
}
}
}
# variables: {"item":{"__typename":"Item","id":1},"cart":{"__typename":"Cart","id":1}}
mutation Checkout ($cart: _ResourceInput!){
_action(action: checkout, subjects: [$cart]){
... on Cart {
id
items {
id
}
}
}
}
# variables: {"cart":{"__typename":"Cart","id":1}}