Skip to content

Commit

Permalink
Add missing docs, deprecate @discriminationAlias
Browse files Browse the repository at this point in the history
Signed-off-by: Dmitriy Lazarev <[email protected]>
  • Loading branch information
wKich committed Sep 13, 2024
1 parent 9b1fc21 commit daa5392
Show file tree
Hide file tree
Showing 16 changed files with 946 additions and 462 deletions.
2 changes: 1 addition & 1 deletion www/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## Effection Website
## HydraphQL Website

### Development

Expand Down
165 changes: 84 additions & 81 deletions www/deno.lock

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions www/docs/codegen.mdx

This file was deleted.

14 changes: 0 additions & 14 deletions www/docs/collections.mdx

This file was deleted.

25 changes: 14 additions & 11 deletions www/docs/discriminates.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -88,28 +88,27 @@ option. With that option HydraphQL will generate opaque types for all interfaces
const application = await createApplication({ generateOpaqueTypes: true });
```

### `@discriminationAlias`
### Discrimination aliases

By default value from `with` argument is used to find a type as-is or converted
to PascalCase. And it's fairly enough for most cases. But sometimes you need to
match the value with a type that has a different name. In this case, you can use
`@discriminationAlias` directive.
match the value with a type that has a different name. In this case, you can define
`aliases` argument.

```graphql
interface API
@implements(interface: "Node")
@discriminates(with: "spec.type")
@discriminationAlias(from: "openapi", to: "OpenAPI") {
@discriminates(with: "spec.type", aliases: [{ from: "grpc", to: "GrpcAPI" }]) {
# ...
}

type OpenAPI @implements(interface: "API") {
type GrpcAPI @implements(interface: "API") {
# ...
}
```

This means, when `spec.type` equals to `openapi`, the `API` interface will be
resolved to `OpenAPI` type.
This means, when `spec.type` equals to `gprc`, the `API` interface will be
resolved to `GrpcAPI` type.

### Using `@discriminates` with multiple data sources

Expand All @@ -128,9 +127,13 @@ const loader = createLoader({

```graphql
extend interface Node
@discriminates(with: "__source")
@discriminationAlias(value: "MyApi", type: "MyApiNode")
@discriminationAlias(value: "AnotherApi", type: "AnotherApiNode") {}
@discriminates(
with: "__source",
aliases: [
{ value: "MyApi", type: "MyApiNode" },
{ value: "AnotherApi", type: "AnotherApiNode" }
]
) {}

type MyApiNode @implements(interface: "Node") {
# ...
Expand Down
21 changes: 12 additions & 9 deletions www/docs/extending.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,12 @@ The GraphQL API provides 2 syntaxes for defining edges:

Use one-to-one syntax when a node is related to only one node. For example,
a component can have only one owner is expressed in the following way. For more
information checkout [`@resolve`][resolve], There is also [`@relation`][relation] directive
implemented in the [Backstage Catalog GraphQL plugin][catalog-module] that resolves nodes
with slightly different way.
information checkout [`@relation`][relation], There is also [`@resolve`][resolve] directive
that could be used for resolving nodes from 3rd party data sources.

```graphql
type Component {
owner: User @resolve(at: "ownerId")
owner: User @relation(name: "ownedBy")
}
```

Expand All @@ -59,11 +58,11 @@ section for more information.

```graphql
type Component {
modules: [Module!] @resolve(at: "modules")
modules: [Module!] @relation(name: "modulesOf")
}

type Group {
members: Connection @resolve(at: "members", from: "UserAPI")
members: Connection @relation(name: "hasMember", nodeType: "User")
}
```

Expand Down Expand Up @@ -249,9 +248,13 @@ server.listen(4000, () => {

```graphql
extend interface Node
@discriminates(with: "__source")
@discriminationAlias(value: "MyApi", type: "MyApiNode")
@discriminationAlias(value: "Catalog", type: "Entity")
@discriminates(
with: "__source",
aliases: [
{ value: "MyApi", type: "MyApiNode" },
{ value: "Catalog", type: "Entity" }
]
)

type Entity @implements(interface: "Node") {
title: String @field(at: "metadata.title")
Expand Down
12 changes: 8 additions & 4 deletions www/docs/hydraphql.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -269,10 +269,14 @@ In the last step we need to update our schema

```graphql
extend interface Node
@discriminates(with: "__source")
@discriminationAlias(value: "Assets", type: "Asset")
@discriminationAlias(value: "Markets", type: "Market")
@discriminationAlias(value: "Exchanges", type: "Exchange") {}
@discriminates(
with: "__source",
aliases: [
{ value: "Assets", type: "Asset" },
{ value: "Markets", type: "Market" },
{ value: "Exchanges", type: "Exchange" }
]
) {}

type Asset @implements(interface: "Node") {
symbol: String! @field
Expand Down
Loading

0 comments on commit daa5392

Please sign in to comment.