Repository navigation
Feature: Tiled Graph Api Client - #71
Conversation
✅ Test ResultsAll tests passed! Complete Test Suite Coverage:
Test Environment: Node.js 20.x |
|
|
||
| return useTiledQuery({ | ||
| queryKey: tiledQueryKeys.graph(scope, { op: 'raw', document, variables: vars }), | ||
| fetch: (client, request) => |
There was a problem hiding this comment.
(From Codex for your review)
[P1] Reject mutation documents in the query hook
The hook forwards any nonblank document to graphql(), including mutations. Pasting a mutation into the playground’s raw-query editor therefore executes a write automatically, bypassing mutation controls. Refetching, polling, or remounting can repeat that write. I reproduced execution twice through the query hook. Validate that the document selects a query operation before sending it.
| >, | ||
| requestOptions?: TiledRequestOptions, | ||
| ): UseMutationResult<TResult, TiledHookError, TiledGraphQLMutationVariables, TContext> { | ||
| return useTiledMutation({ |
There was a problem hiding this comment.
(From codex for your review)
[P2] Invalidate graph queries after partial mutation failures
This delegates to useTiledMutation, which invalidates only on success. A raw mutation can commit its first field and fail a later field; graphql() then rejects, leaving cached graph reads unchanged despite the committed write. I reproduced the missing invalidation with a resolver-error response. Refresh graph queries on execution failures that may contain partial writes, while preserving the error for callers.
|
Manually tested:
The only other thing I noticed is no clear way of obtaining the path to a Tiled catalogue node when an entity is NodeBound. This would be needed for going from an entity about a scan to then querying the scan itself from the regular REST api |
✅ Test ResultsAll tests passed! Complete Test Suite Coverage:
Test Environment: Node.js 20.x |
|
Looks good! Tested the bindEntity and verified the uri is exposed as expected. One last comment is to just export the new hooks as named hooks directly in src/index (useTiledBindGraphEntityMutation and useTiledGraphNodeEntitiesQuery) and also the TiledGraphOperationKind type. |
✅ Test ResultsAll tests passed! Complete Test Suite Coverage:
Test Environment: Node.js 20.x |
* install graphql * Create graph schema, types, and ops document * Graph client methods and registry * Add graph hooks, playground entries, and unit tests * Add to skills and README * Document constraint to tiled v0.2.19 * Add client methods for binding to node * Determine operation kinds and invalidate on error * Export new hooks and TiledGraphOperationKind type
Tiled graph of links support in the Tiled API client
Adds Finch support for Tiled's graph of links - allowing for the creation of entities, links, and namespaces. It goes through the same
TiledApiClient, auth, 401 refresh, interceptors and TanStack cache as the rest ofsrc/api/tiled.Built against
mainat bluesky/tiled@849c984a.How Tiled's graph works
{origin}/api/graphql, outside/api/v1, so it isn't inopenapi.json. It's only mounted on catalog-backed servers.entityType,name, optionaluriand JSONproperties. They can be bound to a catalog node (nodePathParts), in which case deleting the node deletes the entity. Ids are assigned by the server.schema→https://schema.org/) makes CURIEs expand on write and compact on read. This applies to predicates and to the keys ofproperties. Register namespaces before writing, or terms are stored as literal text.limit/offset(default 100), with no total count and no next-page signal. A short page means the end.errorsarray. Reads never return 401; the server filters what the caller can see.What's in this PR
useTiledGraphQLQuery/useTiledGraphQLMutationfor nested selectionshooks/graphHooks.tscreateTiledGraphEntity,getTiledGraphLinks,tiledGraphQL, …)client/facade.tsgraphql()transport (maps GraphQLerrorstoTiledApiErrorwithgraphqlCode)client/TiledApiClient.tsgraph/operations.tsgraph/schema.graphql,graph/README.mdtypes/graph.ts,types/errors.tsgraphcache root; every graph write refreshes it, and so doesdeleteNode(bound entities cascade)hooks/queryKeys.ts,hooks/invalidation.tsTILED_GRAPH_ENDPOINTS, kept apart from the spec-checked REST registry)endpoints/graphEndpoints.tscomponents/TiledQueryPlayground/README.md("Graph of links"),SKILLS.md,stories/TiledHooks.mdgraphqlis added as a devDependency only, for schema validation in tests. Nothing shipped imports it, so consumers install nothing new.How to test
Unit tests
TiledGraph.test.tsx(20 tests):schema.graphql, and that every schema operation is implemented;nullclears it), 401 refresh;TiledConnectionStorageand a few non-Tiled suites already fail onmainunder Node 25 (localStorage.getItem is not a function). This PR doesn't affect them.Against a real server. The graph isn't in a Tiled release yet, so install upstream
main:GraphiQL: open http://localhost:8000/api/graphql and add the header
{"Authorization": "Apikey secret"}.Playground: run
npm run dev, open the Tiled Queries tab, and connect tohttp://localhost:8000/api/v1with keysecret. The graph hooks are under "Graph of links".From code:
Planned structure: where vocabularies live
Finch is the generic library that beamline UIs depend on, so it should not hardcode any group's predicates. The plan:
Finch (this PR): moves entities and links. It changes only when Tiled's graph API changes.
A shared ALS vocabulary repo :
forge:namespace) and their rules (e.g. a sampleschema:isPartOfexactly one project);createTiledGraphEntity/createTiledGraphLink;UI repos (beamline apps) depend on both. Finch provides the client and hooks; the vocabulary package provides the terms:
Follow-ups
graph/schema.graphqlwhen #1499 / #1500 merge; the tests will name what changed.