Skip to content

Commit

Permalink
add descriptions for subgraph directives (#3095)
Browse files Browse the repository at this point in the history
Took the text from our docs

https://www.apollographql.com/docs/federation/federated-schemas/federated-directives/#override
<!--
First, 🌠 thank you 🌠 for taking the time to consider a contribution to
Apollo!

Here are some important details to follow:

* ⏰ Your time is important
To save your precious time, if the contribution you are making will
take more than an hour, please make sure it has been discussed in an
        issue first. This is especially true for feature requests!

* 💡 Features
Feature requests can be created and discussed within a GitHub Issue.
Be sure to search for existing feature requests (and related issues!)
prior to opening a new request. If an existing issue covers the need,
please upvote that issue by using the 👍 emote, rather than opening a
        new issue.

* 🕷 Bug fixes
These can be created and discussed in this repository. When fixing a
bug,
please _try_ to add a test which verifies the fix. If you cannot, you
should
still submit the PR but we may still ask you (and help you!) to create a
test.

* Federation versions
Please make sure you're targeting the federation version you're opening
the PR for. Federation 2 (alpha) is currently located on the `main`
branch and prior versions of Federation live on the `version-0.x`
branch.

* 📖 Contribution guidelines
Follow
https://github.com/apollographql/federation/blob/HEAD/CONTRIBUTING.md
when submitting a pull request. Make sure existing tests still pass, and
add
        tests for all new behavior.

* ✏️ Explain your pull request
Describe the big picture of your changes here to communicate to what
        your pull request is meant to accomplish. Provide 🔗 links 🔗 to
        associated issues!

We hope you will find this to be a positive experience! Open source
contribution can be intimidating and we hope to alleviate that pain as
much
as possible. Without following these guidelines, you may be missing
context
that can help you succeed with your contribution, which is why we
encourage
discussion first. Ultimately, there is no guarantee that we will be able
to
merge your pull-request, but by following these guidelines we can try to
avoid disappointment.

-->
  • Loading branch information
cheapsteak authored Jul 24, 2024
1 parent 5f4bb16 commit bb26a78
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/witty-comics-turn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@apollo/subgraph": patch
---

Add descriptions for federation directives
10 changes: 10 additions & 0 deletions subgraph-js/src/directives.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { LinkImportType } from './types';

export const KeyDirective = new GraphQLDirective({
name: 'key',
description: 'Designates an object type as an entity and specifies its key fields. Key fields are a set of fields that a subgraph can use to uniquely identify any instance of the entity.',
locations: [DirectiveLocation.OBJECT, DirectiveLocation.INTERFACE],
isRepeatable: true,
args: {
Expand All @@ -43,16 +44,19 @@ export const KeyDirective = new GraphQLDirective({

export const ExtendsDirective = new GraphQLDirective({
name: 'extends',
description: 'Indicates that an object or interface definition is an extension of another definition of that same type. This directive is for use with GraphQL subgraph libraries that do not support the extend keyword. Most commonly, these are subgraph libraries that generate their schema programmatically instead of using a static .graphql file.',
locations: [DirectiveLocation.OBJECT, DirectiveLocation.INTERFACE],
});

export const ExternalDirective = new GraphQLDirective({
name: 'external',
description: 'Indicates that this subgraph usually can\'t resolve a particular object field, but it still needs to define that field for other purposes. This directive is always used in combination with another directive that references object fields, such as @provides or @requires.',
locations: [DirectiveLocation.OBJECT, DirectiveLocation.FIELD_DEFINITION],
});

export const RequiresDirective = new GraphQLDirective({
name: 'requires',
description: 'Indicates that the resolver for a particular entity field depends on the values of other entity fields that are resolved by other subgraphs. This tells the router that it needs to fetch the values of those externally defined fields first, even if the original client query didn\'t request them.',
locations: [DirectiveLocation.FIELD_DEFINITION],
args: {
fields: {
Expand All @@ -63,6 +67,7 @@ export const RequiresDirective = new GraphQLDirective({

export const ProvidesDirective = new GraphQLDirective({
name: 'provides',
description: 'Specifies a set of entity fields that a subgraph can resolve, but only at a particular schema path (at other paths, the subgraph can\'t resolve those fields). If a subgraph can always resolve a particular entity field, do not apply this directive. Using this directive is always an optional optimization. It can reduce the total number of subgraphs that your router needs to communicate with to resolve certain operations, which can improve performance.',
locations: [DirectiveLocation.FIELD_DEFINITION],
args: {
fields: {
Expand All @@ -73,6 +78,7 @@ export const ProvidesDirective = new GraphQLDirective({

export const TagDirective = new GraphQLDirective({
name: 'tag',
description: 'Applies arbitrary string metadata to a schema location. Custom tooling can use this metadata during any step of the schema delivery flow, including composition, static analysis, and documentation. The GraphOS Enterprise contracts feature uses @tag with its inclusion and exclusion filters.',
locations: [
DirectiveLocation.FIELD_DEFINITION,
DirectiveLocation.OBJECT,
Expand All @@ -96,11 +102,13 @@ export const TagDirective = new GraphQLDirective({

export const ShareableDirective = new GraphQLDirective({
name: 'shareable',
description: 'Indicates that an object type\'s field is allowed to be resolved by multiple subgraphs (by default in Federation 2, object fields can be resolved by only one subgraph).',
locations: [DirectiveLocation.FIELD_DEFINITION, DirectiveLocation.OBJECT],
});

export const LinkDirective = new GraphQLDirective({
name: 'link',
description: 'This directive links definitions from an external specification to this schema.',
locations: [DirectiveLocation.SCHEMA],
args: {
url: {
Expand All @@ -114,6 +122,7 @@ export const LinkDirective = new GraphQLDirective({

export const InaccessibleDirective = new GraphQLDirective({
name: 'inaccessible',
description: 'Indicates that a definition in the subgraph schema should be omitted from the router\'s API schema, even if that definition is also present in other subgraphs. This means that the field is not exposed to clients at all.',
locations: [
DirectiveLocation.FIELD_DEFINITION,
DirectiveLocation.OBJECT,
Expand All @@ -130,6 +139,7 @@ export const InaccessibleDirective = new GraphQLDirective({

export const OverrideDirective = new GraphQLDirective({
name: 'override',
description: 'Indicates that an object field is now resolved by this subgraph instead of another subgraph where it\'s also defined. This enables you to migrate a field from one subgraph to another.',
locations: [DirectiveLocation.FIELD_DEFINITION],
args: {
from: {
Expand Down

0 comments on commit bb26a78

Please sign in to comment.