code.vegaprotocol.io/vega@v0.79.0/datanode/gateway/graphql/README.md (about)

     1  # GraphQL
     2  
     3  The query interface is accessible on `http://localhost:3004/`.
     4  
     5  ## Types
     6  
     7  ### Dates (time.Time)
     8  * Serialization type: `String`
     9  
    10  **Note**
    11  Use `vegatime.Format(vegatime.UnixNano(myDate))` to properly convert it.
    12  
    13  ### How to's?
    14  
    15  ### Add new GraphQL type
    16  1. Add the new type in `schema.graphql`
    17  2. Add binding between golang model and GraphQL type in `gqlgen.yml`
    18  3. Generate the GraphQL model and resolver with `make gqlgen`
    19  4. Create a new golang file `my_type_resolver.go`
    20  5. Implement the `MyTypeResolver` interface
    21      * This interface is located in `generated.go`
    22  6. Add a method `MyType()` on struct `VegaResolverRoot` in `resolvers.go`, 
    23     as follows :
    24  
    25  ```golang
    26  func (r *VegaResolverRoot) MyType() MyTypeResolver {
    27      return (*myTypeResolver)(r)
    28  }
    29  ```
    30  
    31  ### Add a new query?
    32  1. Add a new query in `schema.graphql` in the `Query` type
    33  2. Generate the GraphQL model and resolver with `make gqlgen`
    34  3. Add a method `MyType()` on struct `myQueryResolver` in `resolvers.go`,
    35     as follows :
    36  
    37  ```golang
    38  func (r *myQueryResolver) MyType() types.MyType {
    39  	res, err := r.tradingDataClient.MyType(
    40  		ctx, &protoapi.MyTypeRequest{Id: id},
    41      )
    42      if err != nil {
    43     	    return nil, err
    44      }
    45     
    46     return res.MyType, nil
    47  }
    48  ```