...

Text file src/github.com/99designs/gqlgen/plugin/federation/readme.md

Documentation: github.com/99designs/gqlgen/plugin/federation

     1# Federation plugin
     2
     3Add support for graphql federation in your graphql Go server!
     4
     5TODO(miguel): add details.
     6
     7# Tests
     8There are several different tests. Some will process the configuration file directly.  You can see those in the `federation_test.go`.  There are also tests for entity resolvers, which will simulate requests from a federation server like Apollo Federation.
     9
    10Running entity resolver tests.
    111. Go to `plugin/federation`
    122. Run the command `go generate`
    133. Run the tests with `go test ./...`.
    14
    15# Architecture
    16
    17TODO(miguel): add details.
    18
    19# Entity resolvers - GetMany entities
    20
    21The federation plugin implements `GetMany` semantics in which entity resolvers get the entire list of representations that need to be resolved. This functionality is currently optin tho, and to enable it you need to specify the directive `@entityResolver` in the federated entity you want this feature for.  E.g.
    22
    23```
    24directive @entityResolver(multi: Boolean) on OBJECT
    25
    26type MultiHello @key(fields: "name") @entityResolver(multi: true) {
    27    name: String!
    28}
    29```
    30
    31That allows the federation plugin to generate `GetMany` resolver function that can take a list of representations to be resolved.
    32
    33From that entity type, the resolver function would be
    34
    35```
    36func (r *entityResolver) FindManyMultiHellosByName(ctx context.Context, reps []*generated.ManyMultiHellosByNameInput) ([]*generated.MultiHello, error) {
    37  /// <Your code to resolve the list of items>
    38}
    39```
    40
    41**Note:**
    42If you are using `omit_slice_element_pointers: true` option in your config yaml, your `GetMany` resolver will still generate in the example above the same signature `FindManyMultiHellosByName(ctx context.Context, reps []*generated.ManyMultiHellosByNameInput) ([]*generated.MultiHello, error)`. But all other instances will continue to honor `omit_slice_element_pointers: true`

View as plain text