code.vegaprotocol.io/vega@v0.79.0/datanode/gateway/graphql/doc.go (about) 1 // Copyright (C) 2023 Gobalsky Labs Limited 2 // 3 // This program is free software: you can redistribute it and/or modify 4 // it under the terms of the GNU Affero General Public License as 5 // published by the Free Software Foundation, either version 3 of the 6 // License, or (at your option) any later version. 7 // 8 // This program is distributed in the hope that it will be useful, 9 // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 // GNU Affero General Public License for more details. 12 // 13 // You should have received a copy of the GNU Affero General Public License 14 // along with this program. If not, see <http://www.gnu.org/licenses/>. 15 16 // Package gql contains code for running the GraphQL-to-gRPC gateway. 17 // 18 // In order to add a new GraphQL endpoint, add an entry to either the 19 // `Mutation`, `Query` or `Subscription` sections of 20 // `gateway/graphql/schema.graphql`. Example: 21 // 22 // # SomeNewEndpoint does something 23 // somenewendpoint( 24 // # somestring 25 // someStr: String!, 26 // # someint 27 // someInt: Int! 28 // ): SomeNewEndpointResponse! 29 // 30 // type SomeNewEndpointResponse { 31 // someAnswer: String! 32 // someStringList: [String!] 33 // } 34 // 35 // Then run `make gqlgen`. 36 // 37 // Your new endpoint above will require a `SomeNewEndpointRequest` and `SomeNewEndpointResponse` message to be defined in the trading.proto file. 38 // Once this is defined you can run `make proto` to generate the structures required to add the resolvers below. 39 // e.g. 40 // 41 // message SomeNewEndpointRequest { 42 // string orderID = 1; 43 // string referenceID = 2; 44 // } 45 // 46 // message SomeNewEndpointResponse { 47 // vega.Order order = 1; 48 // } 49 // 50 // Also a function definition needs to be defined in the trading.proto to show the parameters and return strutures for the new function 51 // e.g. rpc SomeNewEndpoint (SomeNewEndpointRequest) returns (SomeNewEndpointResponse) 52 // 53 // Next, in `gateway/graphql/resolvers.go`, add the endpoint to the 54 // `TradingClient` interface if the new endpoint is a mutation, else add it to TradingDataClient if is it just a query, 55 // and add a function implementation, using the 56 // function definition from `generated.go`. Example: 57 // 58 // type TradingClient interface { 59 // // ... 60 // SomeNewEndpoint(context.Context, *api.SomeNewEndpointRequest, ...grpc.CallOption) (*api.SomeNewEndpointResponse, error) 61 // // ... 62 // } 63 // 64 // // <<MQS>> is one of: Mutation, Query, Subscription 65 // func (r *My<<MQS>>Resolver) SomeNewEndpoint(ctx context.Context, someStr string, someInt int64) (*SomeNewEndpointResponse, error) { 66 // req := &protoapi.SomeNewEndpointRequest{ 67 // // ... 68 // } 69 // 70 // response, err := r.tradingClient.SomeNewEndpoint(ctx, req) 71 // if err != nil { 72 // return nil, err 73 // } 74 // 75 // return &SomeNewEndpointResponse{/* ... */}, nil 76 // } 77 // 78 // Now add the new function to the `trading.go` or `trading_data.go` package to actually perform the work 79 // 80 // Lastly, make sure mocks are up to date, then run tests: `make mocks test` 81 package gql