Repository navigation
Structural interfaces across schemas; raise any Error-shaped value - #306
Merged
Merged
Conversation
An interface declared in Dang is now structural: a value of any object or interface type with its fields, public and of fitting types, is a value of the interface, whether or not its type says `implements`, and whichever schema it comes from. A union of such types is one too, unless a schema declares it: a handle on a schema's union has no fields to read. That makes Dang's interfaces the way to write one interface over types from different schemas, none of which can name it. Interfaces a GraphQL schema declares stay nominal: the server decides which types implement them. hm asks a structural want (hm.StructuralType) after the supertypes. The pairs a check assumes are threaded on its own stack, so recursive shapes are judged coinductively and concurrent checks share nothing. The check pins no type: the interface's type variables are skolemized, and an answer binding anything but the field's own freshened variables is refused. Type patterns go through the same question, statically and at runtime. Merging is unchanged: branches of two types that only have an interface's shape still widen to a union, and a list of them needs one cast to it. There is no version gate: the interpreter can't branch on one. Most code only gains programs, but an interface arm of a case or rescue now takes values of the shape, so an arm after it for such a type is unreachable, and in an operand also holding a declared implementation, such a value no longer falls through to a later arm. Signed-off-by: Alex Suraci <[email protected]>
With Error structural, any type with a public `message: String!` is an
error, a GraphQL schema's own error type included: Dagger's Error raises
and rescues as one, and the raised value is the very object, for the host
to read back. Error() can neither query nor call, so a message that takes
either, a GraphQL object's or an object's computed one, is read when the
error is raised, and so are those along its explicit `cause` chain, which
the uncaught report shows. A message that fails to read is reported as
such rather than replacing the error, so a rescue still matches it by type.
Raising a type without the shape says what it lacks.
A rescued error raised again as it was is now that error again, with its
message, its causes, and the Go error it was classified from, as
RaisedError.Origin: after `rescue { e: GraphQLError! => raise e }`, the
GraphQL error with its extensions, for a host to report as if nothing had
rescued it. It is not Unwrap, which would let errors.As find the original
failure's source location in place of the raise's.
Signed-off-by: Alex Suraci <[email protected]>
The interfaces page frames Dang's interfaces as the way to write one across schemas, with what `implements` still adds, and the errors page says any value of Error's shape raises, a schema's own error type included. The 2.5 release notes list structural interfaces and the case arms they can change, and the skills follow. Signed-off-by: Alex Suraci <[email protected]>
Deploying dang with
|
| Latest commit: |
e1a4ea7
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://8f711528.dang-3kk.pages.dev |
| Branch Preview URL: | https://structural-interfaces.dang-3kk.pages.dev |
dang fmt puts a blank line after the pick function. Signed-off-by: Alex Suraci <[email protected]>
vito
added a commit
that referenced
this pull request
Nov 12, 2026
#306 added its sections to the 2.5 notes. The lede, checklist, Go embedders section and sources now cover it too: structural interfaces in the lede, a checklist step for case arms an interface arm now shadows, RaisedError.Origin for hosts, and #306 in the sources, verified at 496a3b6. Signed-off-by: Alex Suraci <[email protected]>
This was referenced Nov 12, 2026
vito
added a commit
that referenced
this pull request
Nov 13, 2026
#306 added its sections to the 2.5 notes. The lede, checklist, Go embedders section and sources now cover it too: structural interfaces in the lede, a checklist step for case arms an interface arm now shadows, RaisedError.Origin for hosts, and #306 in the sources, verified at 496a3b6. Signed-off-by: Alex Suraci <[email protected]>
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Interfaces declared in Dang are now structural. A type that has an interface's fields is a value of it, with or without
implements, and whichever schema it comes from. This makes Dang's interfaces the way to write one interface over types from different schemas. Interfaces a GraphQL schema declares stay nominal.The prelude's
Erroris one of these interfaces, so any type with a publicmessage: String!can be raised, including a schema's own error type. In a Dagger module's entrypoint,raisecan now take aDagger.Errordirectly. The engine gets back the very object that was raised, with all its values. Before, an entrypoint could raise only a message.Structural conformance
A type has an interface's shape when every interface field is a public field of the type, with a type that fits by the rules
implementsalready checks:A union has the shape when each of its members does. A schema's union doesn't qualify, because a handle on it has no fields until the server says what it holds.
How it works:
hm.assignableasks a want that implementshm.StructuralType, after checking supertypes.case/rescuetype patterns ask the same question, both statically (moduleFits,resolveInterfaceTypePattern) and at runtime (matchesType).[(a :: Named!), b].let) field, or the field whose type doesn't fit.There is no version gate, since the interpreter never branches on version. The v2.5 release notes list the two ways a
caseorrescuearm on an interface can change: an arm placed after it for a type of its shape is now unreachable, and in an operand that also holds a declared implementation, a value of the shape takes the interface's arm.Raising
Error()can't make a query. The same goes for an object whosemessageis a method, and for each link of an explicitcausechain, which the uncaught report now shows.RaisedError.Origin().e: GraphQLError! => raise e, a host can still report the GraphQL error with its extensions.Unwrap, which would leterrors.Asfind the original failure's source location instead of the raise site.Docs
dang-languageanddang-internalsskills.Testing
tests/test_interface_structural.dangcovers plain types, methods, generics, unions, recursive shapes, interface-to-interface conformance, casts, type patterns, and raising.pkg/dang/structural_test.go, against a fake schema, covers:ErrorOriginidpkg/dang,pkg/hm,tests,docsandfmt/stalepass.