-
Notifications
You must be signed in to change notification settings - Fork 110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add metadata to hive ui with linked directive support #6517
Open
jdolle
wants to merge
13
commits into
main
Choose a base branch
from
hive-metadata
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+869
−187
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
69b6d47
feat: add metadata to hive ui with linked directive support
jdolle 00f1836
fix typo
jdolle f6bcd9b
Improve metadata integration tests
jdolle 271ebc2
Remove try/catch
jdolle 5b3a453
Merge branch 'main' into hive-metadata
jdolle 2f6bd1e
prettier
jdolle e980c6d
Add source of metadata; adjust UI to indicate the source
jdolle 604e5d4
Fix typecheck
jdolle 071129d
Merge branch 'main' into hive-metadata
jdolle 7927741
Update packages/web/app/src/components/target/explorer/super-graph-me…
jdolle 87ed83f
Add react import
jdolle 4c62d66
Merge branch 'main' into hive-metadata
jdolle 6c5c165
Remove unnecessary tooltip provider
jdolle File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,221 @@ | ||
import { getServiceHost } from 'testkit/utils'; | ||
import type { SchemaBuilderApi } from '@hive/schema'; | ||
import { createTRPCProxyClient, httpLink } from '@trpc/client'; | ||
|
||
const host = | ||
process.env['SCHEMA_SERVICE_HOST_OVERRIDE'] || | ||
(await getServiceHost('schema', 3002).then(r => `http://${r}`)); | ||
|
||
const client = createTRPCProxyClient<SchemaBuilderApi>({ | ||
links: [ | ||
httpLink({ | ||
url: host + `/trpc`, | ||
fetch, | ||
}), | ||
], | ||
}); | ||
|
||
describe('schema service can process metadata', async () => { | ||
const result = await client.composeAndValidate.mutate({ | ||
type: 'federation', | ||
native: true, | ||
schemas: [ | ||
{ | ||
raw: /* GraphQL */ ` | ||
extend schema | ||
@link(url: "https://specs.apollo.dev/link/v1.0") | ||
@link(url: "https://specs.apollo.dev/federation/v2.3") | ||
@link(url: "https://specs.graphql-hive.com/hive/v1.0", import: ["@meta"]) | ||
@meta(name: "schema", content: "user") | ||
|
||
directive @meta( | ||
name: String! | ||
content: String! | ||
) repeatable on SCHEMA | OBJECT | INTERFACE | FIELD_DEFINITION | ||
|
||
type Query { | ||
user: User @meta(name: "field", content: "user") | ||
} | ||
|
||
type User @meta(name: "type", content: "user") { | ||
id: ID! | ||
name: String @meta(name: "field", content: "User.name") | ||
} | ||
`, | ||
source: 'user.graphql', | ||
url: null, | ||
}, | ||
{ | ||
raw: /* GraphQL */ ` | ||
extend schema | ||
@link(url: "https://specs.apollo.dev/link/v1.0") | ||
@link(url: "https://specs.apollo.dev/federation/v2.1") | ||
@link(url: "https://specs.graphql-hive.com/hive/v1.0", import: ["@meta"]) | ||
@meta(name: "schema", content: "foo") | ||
|
||
directive @meta( | ||
name: String! | ||
content: String! | ||
) repeatable on SCHEMA | OBJECT | INTERFACE | FIELD_DEFINITION | ||
|
||
type Query { | ||
foo: String | ||
} | ||
`, | ||
source: 'foo.graphql', | ||
url: null, | ||
}, | ||
], | ||
external: null, | ||
contracts: null, | ||
}); | ||
|
||
test('@meta does not need to be in supergraph', () => { | ||
expect(result.supergraph).toMatchInlineSnapshot(` | ||
schema | ||
@link(url: "https://specs.apollo.dev/link/v1.0") | ||
@link(url: "https://specs.apollo.dev/join/v0.3", for: EXECUTION) | ||
|
||
|
||
|
||
|
||
|
||
@link(url: "https://specs.graphql-hive.com/hive/v1.0", import: ["@meta"]) | ||
{ | ||
query: Query | ||
|
||
|
||
} | ||
|
||
|
||
directive @join__enumValue(graph: join__Graph!) repeatable on ENUM_VALUE | ||
|
||
directive @join__field( | ||
graph: join__Graph | ||
requires: join__FieldSet | ||
provides: join__FieldSet | ||
type: String | ||
external: Boolean | ||
override: String | ||
usedOverridden: Boolean | ||
) repeatable on FIELD_DEFINITION | INPUT_FIELD_DEFINITION | ||
|
||
directive @join__graph(name: String!, url: String!) on ENUM_VALUE | ||
|
||
directive @join__implements( | ||
graph: join__Graph! | ||
interface: String! | ||
) repeatable on OBJECT | INTERFACE | ||
|
||
directive @join__type( | ||
graph: join__Graph! | ||
key: join__FieldSet | ||
extension: Boolean! = false | ||
resolvable: Boolean! = true | ||
isInterfaceObject: Boolean! = false | ||
) repeatable on OBJECT | INTERFACE | UNION | ENUM | INPUT_OBJECT | SCALAR | ||
|
||
directive @join__unionMember(graph: join__Graph!, member: String!) repeatable on UNION | ||
|
||
scalar join__FieldSet | ||
|
||
|
||
directive @link( | ||
url: String | ||
as: String | ||
for: link__Purpose | ||
import: [link__Import] | ||
) repeatable on SCHEMA | ||
|
||
scalar link__Import | ||
|
||
enum link__Purpose { | ||
""" | ||
\`SECURITY\` features provide metadata necessary to securely resolve fields. | ||
""" | ||
SECURITY | ||
|
||
""" | ||
\`EXECUTION\` features provide metadata necessary for operation execution. | ||
""" | ||
EXECUTION | ||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
enum join__Graph { | ||
FOO_GRAPHQL @join__graph(name: "foo.graphql", url: "") | ||
USER_GRAPHQL @join__graph(name: "user.graphql", url: "") | ||
} | ||
|
||
type Query @join__type(graph: FOO_GRAPHQL) @join__type(graph: USER_GRAPHQL) { | ||
foo: String @join__field(graph: FOO_GRAPHQL) | ||
user: User @join__field(graph: USER_GRAPHQL) | ||
} | ||
|
||
type User @join__type(graph: USER_GRAPHQL) { | ||
id: ID! | ||
name: String | ||
} | ||
`); | ||
}); | ||
|
||
test('metadata is a union from schema, type, and field @meta', () => { | ||
expect(result.schemaMetadata).toMatchInlineSnapshot(` | ||
{ | ||
Query.foo: [ | ||
{ | ||
content: foo, | ||
name: schema, | ||
source: foo.graphql, | ||
}, | ||
], | ||
Query.user: [ | ||
{ | ||
content: user, | ||
name: field, | ||
source: user.graphql, | ||
}, | ||
{ | ||
content: user, | ||
name: schema, | ||
source: user.graphql, | ||
}, | ||
], | ||
User.id: [ | ||
{ | ||
content: user, | ||
name: type, | ||
source: user.graphql, | ||
}, | ||
{ | ||
content: user, | ||
name: schema, | ||
source: user.graphql, | ||
}, | ||
], | ||
User.name: [ | ||
{ | ||
content: User.name, | ||
name: field, | ||
source: user.graphql, | ||
}, | ||
{ | ||
content: user, | ||
name: type, | ||
source: user.graphql, | ||
}, | ||
{ | ||
content: user, | ||
name: schema, | ||
source: user.graphql, | ||
}, | ||
], | ||
} | ||
`); | ||
}); | ||
}); |
112 changes: 63 additions & 49 deletions
112
packages/libraries/cli/examples/federation.products.graphql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,74 @@ | ||
enum CURRENCY_CODE { | ||
USD | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I assume the prior version was for Federation 1? But I couldn't get the two example schemas working locally. I've opted to update them to Federation 2. Let me know if I should make a new version instead. |
||
extend schema | ||
@link( | ||
url: "https://specs.apollo.dev/federation/v2.3" | ||
import: ["@key", "@shareable", "@inaccessible", "@tag"] | ||
) | ||
@link(url: "https://specs.graphql-hive.com/hive/v1.0", import: ["@meta"]) | ||
@meta(name: "priority", content: "tier1") | ||
|
||
directive @meta( | ||
name: String! | ||
content: String! | ||
) repeatable on SCHEMA | OBJECT | INTERFACE | FIELD_DEFINITION | ||
|
||
directive @myDirective(a: String!) on FIELD_DEFINITION | ||
|
||
directive @hello on FIELD_DEFINITION | ||
|
||
type Query { | ||
allProducts: [ProductItf] @meta(name: "owner", content: "hive-team") | ||
product(id: ID!): ProductItf | ||
} | ||
|
||
type Department { | ||
category: ProductCategory | ||
url: String | ||
interface ProductItf implements SkuItf @meta(name: "domain", content: "products") { | ||
id: ID! | ||
sku: String | ||
name: String | ||
package: String | ||
variation: ProductVariation | ||
dimensions: ProductDimension | ||
createdBy: User | ||
hidden: String @inaccessible | ||
oldField: String @deprecated(reason: "refactored out") | ||
} | ||
|
||
type Money { | ||
amount: Float | ||
currencyCode: CURRENCY_CODE | ||
interface SkuItf { | ||
sku: String | ||
} | ||
|
||
""" | ||
Here are some helpful details about your type | ||
""" | ||
type Price { | ||
cost: Money | ||
type Product implements ProductItf & SkuItf | ||
@key(fields: "id") | ||
@key(fields: "sku package") | ||
@key(fields: "sku variation { id }") | ||
@meta(name: "owner", content: "product-team") { | ||
id: ID! @tag(name: "hi-from-products") | ||
sku: String @meta(name: "unique", content: "true") | ||
name: String @hello | ||
package: String | ||
variation: ProductVariation | ||
dimensions: ProductDimension | ||
createdBy: User | ||
hidden: String | ||
reviewsScore: Float! | ||
oldField: String | ||
} | ||
|
||
""" | ||
A number between 0 and 1 signifying the % discount | ||
""" | ||
deal: Float | ||
dealSavings: Money | ||
enum ShippingClass { | ||
STANDARD | ||
EXPRESS | ||
} | ||
|
||
""" | ||
This is an Entity, docs:https://www.apollographql.com/docs/federation/entities/ | ||
You will need to define a __resolveReference resolver for the type you define, docs: https://www.apollographql.com/docs/federation/entities/#resolving | ||
""" | ||
type Product @key(fields: "id") { | ||
type ProductVariation { | ||
id: ID! | ||
title: String | ||
url: String | ||
description: String | ||
price: Price | ||
salesRank(category: ProductCategory = ALL): Int | ||
salesRankOverall: Int | ||
salesRankInCategory: Int | ||
category: ProductCategory | ||
images(size: Int = 1000): [String] | ||
primaryImage(size: Int = 1000): String | ||
} | ||
|
||
enum ProductCategory { | ||
ALL | ||
GIFT_CARDS | ||
ELECTRONICS | ||
CAMERA_N_PHOTO | ||
VIDEO_GAMES | ||
BOOKS | ||
CLOTHING | ||
} | ||
|
||
extend type Query { | ||
bestSellers(category: ProductCategory = ALL): [Product] | ||
categories: [Department] | ||
product(id: ID!): Product | ||
name: String | ||
} | ||
|
||
type ProductDimension @shareable { | ||
size: String | ||
weight: Float | ||
} | ||
|
||
type User @key(fields: "email") { | ||
email: ID! | ||
totalProductsCreated: Int @shareable | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: should this go somewhere into the test kit? 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
possibly... I dont see anywhere in the codebase where we use
SCHEMA_SERVICE_HOST_OVERRIDE
... If anything I assumeRUN_AGAINST_LOCAL_SERVICES
is more practical for us to use for overriding the hosts.I'd be in favor of removing the env var condition in this file and in the
contracts.spec.ts
before moving this into the test kit.