-
Notifications
You must be signed in to change notification settings - Fork 19
/
doc.go
81 lines (80 loc) · 3 KB
/
doc.go
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
// Copyright (C) 2023 Gobalsky Labs Limited
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
// Package gql contains code for running the GraphQL-to-gRPC gateway.
//
// In order to add a new GraphQL endpoint, add an entry to either the
// `Mutation`, `Query` or `Subscription` sections of
// `gateway/graphql/schema.graphql`. Example:
//
// # SomeNewEndpoint does something
// somenewendpoint(
// # somestring
// someStr: String!,
// # someint
// someInt: Int!
// ): SomeNewEndpointResponse!
//
// type SomeNewEndpointResponse {
// someAnswer: String!
// someStringList: [String!]
// }
//
// Then run `make gqlgen`.
//
// Your new endpoint above will require a `SomeNewEndpointRequest` and `SomeNewEndpointResponse` message to be defined in the trading.proto file.
// Once this is defined you can run `make proto` to generate the structures required to add the resolvers below.
// e.g.
//
// message SomeNewEndpointRequest {
// string orderID = 1;
// string referenceID = 2;
// }
//
// message SomeNewEndpointResponse {
// vega.Order order = 1;
// }
//
// Also a function definition needs to be defined in the trading.proto to show the parameters and return strutures for the new function
// e.g. rpc SomeNewEndpoint (SomeNewEndpointRequest) returns (SomeNewEndpointResponse)
//
// Next, in `gateway/graphql/resolvers.go`, add the endpoint to the
// `TradingClient` interface if the new endpoint is a mutation, else add it to TradingDataClient if is it just a query,
// and add a function implementation, using the
// function definition from `generated.go`. Example:
//
// type TradingClient interface {
// // ...
// SomeNewEndpoint(context.Context, *api.SomeNewEndpointRequest, ...grpc.CallOption) (*api.SomeNewEndpointResponse, error)
// // ...
// }
//
// // <<MQS>> is one of: Mutation, Query, Subscription
// func (r *My<<MQS>>Resolver) SomeNewEndpoint(ctx context.Context, someStr string, someInt int64) (*SomeNewEndpointResponse, error) {
// req := &protoapi.SomeNewEndpointRequest{
// // ...
// }
//
// response, err := r.tradingClient.SomeNewEndpoint(ctx, req)
// if err != nil {
// return nil, err
// }
//
// return &SomeNewEndpointResponse{/* ... */}, nil
// }
//
// Now add the new function to the `trading.go` or `trading_data.go` package to actually perform the work
//
// Lastly, make sure mocks are up to date, then run tests: `make mocks test`
package gql