Repository navigation
feat: make module types id-able - #6102
Conversation
6487d81 to
8ffb343
Compare
8ffb343 to
594a063
Compare
|
Justin is on vacation so I'm working on a few updates. One important implication to all this is that proper support for other module objects as inputs + outputs means that we do need to selectively include transitive deps in the schema presented to callers. So if you have a chain of module deps A->B->C ("->" meaning "depends on") like: A: B: C: Then a caller who loads module A also needs schema loaded for module B, which in turn needs schema loaded for module C. This is worth explicitly noting since it does diverge from the previous rule that when you load a given module you only got its schema. This makes the problem of conflicting versions of the same module in the dependency DAG arise again, but only in certain situations. I don't see any obvious ways of avoiding that unless we prevented modules from using another module's types as input/output, which isn't viable. So we'll just need to accept that going forward and deal with it as needed. That being said, I am working on an update to this code so that we only include a dep in the schema presented to callers if that dep actually appears as an input/output/field. This at least allows us to avoid including deps when they are only used in the implementation of functions, which I'd suspect probably ends up being the majority of the cases. In theory we could probably go even further and trace the precise parts of dep schemas that the caller actually needs (any "path" that can lead to the types referred to by the depender in input/output/field), but I think the complication of doing so greatly outweighs the marginal reward, so not pursuing that right now. cc @vito |
|
@sipsma Good point, definitely worth surfacing. It seems like a reasonable and expected outcome, really; if your module directly exposes another module's types, it becomes part of your external contract too. I think this would be much scarier in the previous iteration where modules could extend other types, but right now it seems under control. Just something to keep in mind if/when we consider bringing that back in some form. |
|
@vito after writing more code and thinking through I'm realizing this actually has some very immediate implications in non-obscure cases. If you bear with me a sec, would appreciate a double-check that I'm not overthinking or missing anything obvious 🙂 Example of the problem:
B: type B struct{}
func (b *B) WithObjD(d *ObjD) *B {}C: type C struct{}
func (c *C) WithObjD(d *ObjD) *C {}
So far so good. But now it turns out that
This creates problems. Say you want to now write a module type A struct{}
func (a *A) Fn() error {
d := dag.D().GetObjD("abc", 123)
c := dag.C().WithObjD(d)
b := dag.B().WithObjD(d)
// ...
}The code for If the different versions of This is my current best idea for a short term solution:
We would not be handling every case here yet, but I think it would at least cover the worst case ones? While still enabling this (pretty important) feature and not forcing everyone writing modules to get every single one of their deps all aligned on the exact same version (i.e. git commit) of a module. In the longer term, I think the solution should be at least actual semver for modules, including both auto-detection of breaking changes to the schema and manual bumping of major version in case the implementation changes in some breaking way. I know you were thinking about that already @vito. I'm hoping we nonetheless can still keep this problem relatively simple and not have to go all the way to the NP-Complete problem 😅 (https://research.swtch.com/version-sat). cc @helderco @shykes since there's some potentially wide-ranging implications here. IIRC Helder I think you did a lot of research into these sorts of issues back in the CUE days (?), so appreciate any insights you may have from that if so. |
|
@sipsma Oof, yeah that's complicated. Since it feels like we're slipping down a slope leading to General Purpose Programming Language Problems, I want to play devil's advocate on this point:
You mention this isn't viable, but I want to pretend it is: what if we had the constraint that modules can use other modules, but they can only return their own types and/or core types? i.e., encapsulate or bust Do you have a killer example of a module needing to accept/return another module's types? Aside from the fact that we've considered making the core types themselves a "core" module? I also want to point out that most of the time even in Go you're not using modules that are so tightly coupled together that they directly consume or return another module's types. I'm kind of going out on a limb here; there are probably a ton of counterexamples, but it's not really apples-to-apples, and it still feels right. 🤔 The reason I ask is it feels like you can already get quite far by relying on the core types (containers, files, directories) combined with whatever programming language libraries/dependencies you want to use natively. I'm worried that we're pulling on a thread that will just bring all the complexity in the "high-fidelity" languages into a world that can otherwise be "low-fidelity" glue code. I'm wondering if there should be conscious limitations like this to keep it from becoming twice the mental overhead. Don't want get too preoccupied with whether we could, before wondering whether we should. :P To be clear, making module types ID-able would still make sense in this world, since it a module's API might want to accept its own types as inputs. |
Yeah this has been bouncing around in my head too. I was attempting to avoid it because:
But yeah, I was probably avoiding it a bit too hard; it should definitely be on the table. Thinking about it some more, I suppose another option would be to automatically do the encapsulation for the user. So if module I don't like that... but it would technically solve the problem I think. Maybe there's something along these lines that's good...? |
|
@vito I talked with @aweris about his use case for using objects from other modules as input/output of Functions, was super helpful. It made me realize that his use case and most likely many others could also be satisfied by adding support for interfaces (both on the graphql schema level and in SDKs). In his case he wants to compose different modules in a pattern like: dag.Gale().WithStep(dag.Foo().Step()).WithStep(dag.Bar().Step())where For a lot of use cases, it makes total sense to just use core types like If the
I need to give this one more round of thought to verify it's sound (and please chime in if anyone has thoughts), but if so my plan will be:
|
|
@sipsma Love that idea - my mind also went to interfaces, but I put the thought on hold when I noticed GraphQL interfaces aren't supported as inputs (which makes sense - objects in general aren't). But if we find a way to figure it out, I really like the semantics of accepting + returning interfaces instead of concrete types. |
Yeah we'll have to fit this into the ID system, similar to how we don't use loadFooInterfaceFromID(id: String!) FooInterface!Where it accepts any object's ID and will return the interface representation of it if the object matches that interface, error otherwise. I think we have most of the scaffolding in place to support that at this point so hopefully shouldn't be too huge a wrench 🤞 |
594a063 to
2027bc9
Compare
|
Pushed an additional commit w/ the aforementioned changes here: 2027bc9 |
vito
left a comment
There was a problem hiding this comment.
Just a couple nitpicks, otherwise LGTM!
There was a problem hiding this comment.
nit: Seems like this sanity check should happen in DecodeModule for consistency with (ID).Decode.
| typeName, value, err := resourceid.DecodeModule(id) | |
| if err != nil { | |
| return a, nil | |
| } | |
| if typeName != typeDef.AsObject.Name { | |
| // if we hit this, the module is misbehaving - it's | |
| // declared it returns a different module type than it's | |
| // actually returned | |
| return nil, fmt.Errorf("invalid type name %q, expected %q", typeName, typeDef.AsObject.Name) | |
| } | |
| return value, nil | |
| return resourceid.DecodeModule(id, typeDef.AsObject.Name) |
There was a problem hiding this comment.
Yeah good call (here and related comment below), made this update.
It also got rid of a case where we ignored the error from resourceid.DecodeModule, we just always return an error from that if received here now. AFAICT that's the desirable behavior and the tests pass, so think we're good to go.
There was a problem hiding this comment.
nit: These names feel a little confusing, since they sound like they encode/decode the module itself, but they actually encode/decode a typed object from a module.
Maybe something like this? (building on previous comment)
| func DecodeModule(rest string) (string, any, error) { | |
| func DecodeModuleID(id string, expectedType string) (any, error) { |
(and EncodeModuleID in turn, not so picky about what we call it, I could see DecodeModuleObject or something too)
This feature allows all module declared objects to be converted to a
respective ID-type using the "id" field, and converted from an ID-type
using the "loadFromID" helper. This effectively makes these types
fully idable.
IDs are essentially the contents of the module type's data,
JSON-encoded, and then base64-encoded, similar (but not identical) to
standard IDs. At the moment, they don't share exactly the same codepaths
to normal modules, but this could be adapted to be so in the future. We
also include a note of *what type* generated this ID - this is so we can
prevent type confusion.
Essentially, this enables a number of previously impossible use cases:
1. Returning a custom object from another module from a function
- This case is the simplest - we just extend our conversion that
unpacks all returned IDs from functions into their underlying types
(so while a module returns an XID, it can be queried as if it was X).
2. Accepting a custom object as a parameter to a function
- Because graphql doesn't support creating inline objects, we get
around this in the core api by instead passing IDs everywhere. All
the code-gen is setup to expect this, but module types weren't
IDable, so we failed during schema-checking.
Additionally, we need to transparently convert the ID from the
graphql request into the underlying storage data for the module.
3. Accepting a custom object from another module as a parameter to a
function
- This is the same case as above, but also involves ensuring that we
stitch in the type declarations from the module into our own schema
so that we have the right type.
However, here, we **don't** decode the ID into its underlying
data, it's a foreign type, so the module should only see the ID.
Signed-off-by: Justin Chadwell <[email protected]>
While we now give all module objects ID-ability and enable a module to accept its own objects as function inputs, we are not yet going to allow modules to use objects from other (non-core) modules as function args, function returns or object fields. This is because allowing that results in a caller who depends on a given module A to now not only have access to module A's types but also the types of transitive dependencies. This in turn opens the doors to dependency hell; if two versions of a given module show up multiple times in the full dependency DAG we need some fairly complex dependency resolution logic around which of those versions is exposed to the caller. That problem is famously difficult and while we may need to deal with it someday, it's preferable to avoid it for as long as possible. The idea is to instead add support for interfaces in follow ups, which should unblock many of the use cases that call for interoperability between different module types. The main changes in this commit are to detect when a user tries to do this and give them a descriptive error message in that case. Other related changes are: * an additional integ test case for the situation where there's conflicting versions of a give module in the transitive dependency DAG, which is expected to continue working. * tracking of which module a given schema type was loaded from, which allows us to distinguish between use of a type from core (which is still allowed) and a type from a dependency module. * removal of "Dependencies" from the ExecutableSchema interface we use internally, which overlapped with some of the other changes here and was completely unused (leftover from ancient days during the Cloak project). Signed-off-by: Erik Sipsma <[email protected]>
Signed-off-by: Erik Sipsma <[email protected]>
2027bc9 to
4fc8684
Compare
* feat: make module types id-able
This feature allows all module declared objects to be converted to a
respective ID-type using the "id" field, and converted from an ID-type
using the "loadFromID" helper. This effectively makes these types
fully idable.
IDs are essentially the contents of the module type's data,
JSON-encoded, and then base64-encoded, similar (but not identical) to
standard IDs. At the moment, they don't share exactly the same codepaths
to normal modules, but this could be adapted to be so in the future. We
also include a note of *what type* generated this ID - this is so we can
prevent type confusion.
Essentially, this enables a number of previously impossible use cases:
1. Returning a custom object from another module from a function
- This case is the simplest - we just extend our conversion that
unpacks all returned IDs from functions into their underlying types
(so while a module returns an XID, it can be queried as if it was X).
2. Accepting a custom object as a parameter to a function
- Because graphql doesn't support creating inline objects, we get
around this in the core api by instead passing IDs everywhere. All
the code-gen is setup to expect this, but module types weren't
IDable, so we failed during schema-checking.
Additionally, we need to transparently convert the ID from the
graphql request into the underlying storage data for the module.
3. Accepting a custom object from another module as a parameter to a
function
- This is the same case as above, but also involves ensuring that we
stitch in the type declarations from the module into our own schema
so that we have the right type.
However, here, we **don't** decode the ID into its underlying
data, it's a foreign type, so the module should only see the ID.
Signed-off-by: Justin Chadwell <[email protected]>
* disallow use of external module types in function+field signatures
While we now give all module objects ID-ability and enable a module to
accept its own objects as function inputs, we are not yet going to allow
modules to use objects from other (non-core) modules as function args,
function returns or object fields.
This is because allowing that results in a caller who depends on a given
module A to now not only have access to module A's types but also the
types of transitive dependencies. This in turn opens the doors to
dependency hell; if two versions of a given module show up multiple
times in the full dependency DAG we need some fairly complex dependency
resolution logic around which of those versions is exposed to the
caller.
That problem is famously difficult and while we may need to deal with it
someday, it's preferable to avoid it for as long as possible.
The idea is to instead add support for interfaces in follow ups, which
should unblock many of the use cases that call for interoperability
between different module types.
The main changes in this commit are to detect when a user tries to do
this and give them a descriptive error message in that case. Other
related changes are:
* an additional integ test case for the situation where there's
conflicting versions of a give module in the transitive dependency
DAG, which is expected to continue working.
* tracking of which module a given schema type was loaded from, which
allows us to distinguish between use of a type from core (which is
still allowed) and a type from a dependency module.
* removal of "Dependencies" from the ExecutableSchema interface we use
internally, which overlapped with some of the other changes here and
was completely unused (leftover from ancient days during the Cloak
project).
Signed-off-by: Erik Sipsma <[email protected]>
* check expected module type name direct in decode
Signed-off-by: Erik Sipsma <[email protected]>
---------
Signed-off-by: Justin Chadwell <[email protected]>
Signed-off-by: Erik Sipsma <[email protected]>
Co-authored-by: Erik Sipsma <[email protected]>
Signed-off-by: Christian Schlatter <[email protected]>
* feat: make module types id-able
This feature allows all module declared objects to be converted to a
respective ID-type using the "id" field, and converted from an ID-type
using the "loadFromID" helper. This effectively makes these types
fully idable.
IDs are essentially the contents of the module type's data,
JSON-encoded, and then base64-encoded, similar (but not identical) to
standard IDs. At the moment, they don't share exactly the same codepaths
to normal modules, but this could be adapted to be so in the future. We
also include a note of *what type* generated this ID - this is so we can
prevent type confusion.
Essentially, this enables a number of previously impossible use cases:
1. Returning a custom object from another module from a function
- This case is the simplest - we just extend our conversion that
unpacks all returned IDs from functions into their underlying types
(so while a module returns an XID, it can be queried as if it was X).
2. Accepting a custom object as a parameter to a function
- Because graphql doesn't support creating inline objects, we get
around this in the core api by instead passing IDs everywhere. All
the code-gen is setup to expect this, but module types weren't
IDable, so we failed during schema-checking.
Additionally, we need to transparently convert the ID from the
graphql request into the underlying storage data for the module.
3. Accepting a custom object from another module as a parameter to a
function
- This is the same case as above, but also involves ensuring that we
stitch in the type declarations from the module into our own schema
so that we have the right type.
However, here, we **don't** decode the ID into its underlying
data, it's a foreign type, so the module should only see the ID.
Signed-off-by: Justin Chadwell <[email protected]>
* disallow use of external module types in function+field signatures
While we now give all module objects ID-ability and enable a module to
accept its own objects as function inputs, we are not yet going to allow
modules to use objects from other (non-core) modules as function args,
function returns or object fields.
This is because allowing that results in a caller who depends on a given
module A to now not only have access to module A's types but also the
types of transitive dependencies. This in turn opens the doors to
dependency hell; if two versions of a given module show up multiple
times in the full dependency DAG we need some fairly complex dependency
resolution logic around which of those versions is exposed to the
caller.
That problem is famously difficult and while we may need to deal with it
someday, it's preferable to avoid it for as long as possible.
The idea is to instead add support for interfaces in follow ups, which
should unblock many of the use cases that call for interoperability
between different module types.
The main changes in this commit are to detect when a user tries to do
this and give them a descriptive error message in that case. Other
related changes are:
* an additional integ test case for the situation where there's
conflicting versions of a give module in the transitive dependency
DAG, which is expected to continue working.
* tracking of which module a given schema type was loaded from, which
allows us to distinguish between use of a type from core (which is
still allowed) and a type from a dependency module.
* removal of "Dependencies" from the ExecutableSchema interface we use
internally, which overlapped with some of the other changes here and
was completely unused (leftover from ancient days during the Cloak
project).
Signed-off-by: Erik Sipsma <[email protected]>
* check expected module type name direct in decode
Signed-off-by: Erik Sipsma <[email protected]>
---------
Signed-off-by: Justin Chadwell <[email protected]>
Signed-off-by: Erik Sipsma <[email protected]>
Co-authored-by: Erik Sipsma <[email protected]>
* feat: make module types id-able
This feature allows all module declared objects to be converted to a
respective ID-type using the "id" field, and converted from an ID-type
using the "loadFromID" helper. This effectively makes these types
fully idable.
IDs are essentially the contents of the module type's data,
JSON-encoded, and then base64-encoded, similar (but not identical) to
standard IDs. At the moment, they don't share exactly the same codepaths
to normal modules, but this could be adapted to be so in the future. We
also include a note of *what type* generated this ID - this is so we can
prevent type confusion.
Essentially, this enables a number of previously impossible use cases:
1. Returning a custom object from another module from a function
- This case is the simplest - we just extend our conversion that
unpacks all returned IDs from functions into their underlying types
(so while a module returns an XID, it can be queried as if it was X).
2. Accepting a custom object as a parameter to a function
- Because graphql doesn't support creating inline objects, we get
around this in the core api by instead passing IDs everywhere. All
the code-gen is setup to expect this, but module types weren't
IDable, so we failed during schema-checking.
Additionally, we need to transparently convert the ID from the
graphql request into the underlying storage data for the module.
3. Accepting a custom object from another module as a parameter to a
function
- This is the same case as above, but also involves ensuring that we
stitch in the type declarations from the module into our own schema
so that we have the right type.
However, here, we **don't** decode the ID into its underlying
data, it's a foreign type, so the module should only see the ID.
Signed-off-by: Justin Chadwell <[email protected]>
* disallow use of external module types in function+field signatures
While we now give all module objects ID-ability and enable a module to
accept its own objects as function inputs, we are not yet going to allow
modules to use objects from other (non-core) modules as function args,
function returns or object fields.
This is because allowing that results in a caller who depends on a given
module A to now not only have access to module A's types but also the
types of transitive dependencies. This in turn opens the doors to
dependency hell; if two versions of a given module show up multiple
times in the full dependency DAG we need some fairly complex dependency
resolution logic around which of those versions is exposed to the
caller.
That problem is famously difficult and while we may need to deal with it
someday, it's preferable to avoid it for as long as possible.
The idea is to instead add support for interfaces in follow ups, which
should unblock many of the use cases that call for interoperability
between different module types.
The main changes in this commit are to detect when a user tries to do
this and give them a descriptive error message in that case. Other
related changes are:
* an additional integ test case for the situation where there's
conflicting versions of a give module in the transitive dependency
DAG, which is expected to continue working.
* tracking of which module a given schema type was loaded from, which
allows us to distinguish between use of a type from core (which is
still allowed) and a type from a dependency module.
* removal of "Dependencies" from the ExecutableSchema interface we use
internally, which overlapped with some of the other changes here and
was completely unused (leftover from ancient days during the Cloak
project).
Signed-off-by: Erik Sipsma <[email protected]>
* check expected module type name direct in decode
Signed-off-by: Erik Sipsma <[email protected]>
---------
Signed-off-by: Justin Chadwell <[email protected]>
Signed-off-by: Erik Sipsma <[email protected]>
Co-authored-by: Erik Sipsma <[email protected]>
* feat: make module types id-able
This feature allows all module declared objects to be converted to a
respective ID-type using the "id" field, and converted from an ID-type
using the "loadFromID" helper. This effectively makes these types
fully idable.
IDs are essentially the contents of the module type's data,
JSON-encoded, and then base64-encoded, similar (but not identical) to
standard IDs. At the moment, they don't share exactly the same codepaths
to normal modules, but this could be adapted to be so in the future. We
also include a note of *what type* generated this ID - this is so we can
prevent type confusion.
Essentially, this enables a number of previously impossible use cases:
1. Returning a custom object from another module from a function
- This case is the simplest - we just extend our conversion that
unpacks all returned IDs from functions into their underlying types
(so while a module returns an XID, it can be queried as if it was X).
2. Accepting a custom object as a parameter to a function
- Because graphql doesn't support creating inline objects, we get
around this in the core api by instead passing IDs everywhere. All
the code-gen is setup to expect this, but module types weren't
IDable, so we failed during schema-checking.
Additionally, we need to transparently convert the ID from the
graphql request into the underlying storage data for the module.
3. Accepting a custom object from another module as a parameter to a
function
- This is the same case as above, but also involves ensuring that we
stitch in the type declarations from the module into our own schema
so that we have the right type.
However, here, we **don't** decode the ID into its underlying
data, it's a foreign type, so the module should only see the ID.
Signed-off-by: Justin Chadwell <[email protected]>
* disallow use of external module types in function+field signatures
While we now give all module objects ID-ability and enable a module to
accept its own objects as function inputs, we are not yet going to allow
modules to use objects from other (non-core) modules as function args,
function returns or object fields.
This is because allowing that results in a caller who depends on a given
module A to now not only have access to module A's types but also the
types of transitive dependencies. This in turn opens the doors to
dependency hell; if two versions of a given module show up multiple
times in the full dependency DAG we need some fairly complex dependency
resolution logic around which of those versions is exposed to the
caller.
That problem is famously difficult and while we may need to deal with it
someday, it's preferable to avoid it for as long as possible.
The idea is to instead add support for interfaces in follow ups, which
should unblock many of the use cases that call for interoperability
between different module types.
The main changes in this commit are to detect when a user tries to do
this and give them a descriptive error message in that case. Other
related changes are:
* an additional integ test case for the situation where there's
conflicting versions of a give module in the transitive dependency
DAG, which is expected to continue working.
* tracking of which module a given schema type was loaded from, which
allows us to distinguish between use of a type from core (which is
still allowed) and a type from a dependency module.
* removal of "Dependencies" from the ExecutableSchema interface we use
internally, which overlapped with some of the other changes here and
was completely unused (leftover from ancient days during the Cloak
project).
Signed-off-by: Erik Sipsma <[email protected]>
* check expected module type name direct in decode
Signed-off-by: Erik Sipsma <[email protected]>
---------
Signed-off-by: Justin Chadwell <[email protected]>
Signed-off-by: Erik Sipsma <[email protected]>
Co-authored-by: Erik Sipsma <[email protected]>
* feat: make module types id-able
This feature allows all module declared objects to be converted to a
respective ID-type using the "id" field, and converted from an ID-type
using the "loadFromID" helper. This effectively makes these types
fully idable.
IDs are essentially the contents of the module type's data,
JSON-encoded, and then base64-encoded, similar (but not identical) to
standard IDs. At the moment, they don't share exactly the same codepaths
to normal modules, but this could be adapted to be so in the future. We
also include a note of *what type* generated this ID - this is so we can
prevent type confusion.
Essentially, this enables a number of previously impossible use cases:
1. Returning a custom object from another module from a function
- This case is the simplest - we just extend our conversion that
unpacks all returned IDs from functions into their underlying types
(so while a module returns an XID, it can be queried as if it was X).
2. Accepting a custom object as a parameter to a function
- Because graphql doesn't support creating inline objects, we get
around this in the core api by instead passing IDs everywhere. All
the code-gen is setup to expect this, but module types weren't
IDable, so we failed during schema-checking.
Additionally, we need to transparently convert the ID from the
graphql request into the underlying storage data for the module.
3. Accepting a custom object from another module as a parameter to a
function
- This is the same case as above, but also involves ensuring that we
stitch in the type declarations from the module into our own schema
so that we have the right type.
However, here, we **don't** decode the ID into its underlying
data, it's a foreign type, so the module should only see the ID.
Signed-off-by: Justin Chadwell <[email protected]>
* disallow use of external module types in function+field signatures
While we now give all module objects ID-ability and enable a module to
accept its own objects as function inputs, we are not yet going to allow
modules to use objects from other (non-core) modules as function args,
function returns or object fields.
This is because allowing that results in a caller who depends on a given
module A to now not only have access to module A's types but also the
types of transitive dependencies. This in turn opens the doors to
dependency hell; if two versions of a given module show up multiple
times in the full dependency DAG we need some fairly complex dependency
resolution logic around which of those versions is exposed to the
caller.
That problem is famously difficult and while we may need to deal with it
someday, it's preferable to avoid it for as long as possible.
The idea is to instead add support for interfaces in follow ups, which
should unblock many of the use cases that call for interoperability
between different module types.
The main changes in this commit are to detect when a user tries to do
this and give them a descriptive error message in that case. Other
related changes are:
* an additional integ test case for the situation where there's
conflicting versions of a give module in the transitive dependency
DAG, which is expected to continue working.
* tracking of which module a given schema type was loaded from, which
allows us to distinguish between use of a type from core (which is
still allowed) and a type from a dependency module.
* removal of "Dependencies" from the ExecutableSchema interface we use
internally, which overlapped with some of the other changes here and
was completely unused (leftover from ancient days during the Cloak
project).
Signed-off-by: Erik Sipsma <[email protected]>
* check expected module type name direct in decode
Signed-off-by: Erik Sipsma <[email protected]>
---------
Signed-off-by: Justin Chadwell <[email protected]>
Signed-off-by: Erik Sipsma <[email protected]>
Co-authored-by: Erik Sipsma <[email protected]>
* feat: make module types id-able
This feature allows all module declared objects to be converted to a
respective ID-type using the "id" field, and converted from an ID-type
using the "loadFromID" helper. This effectively makes these types
fully idable.
IDs are essentially the contents of the module type's data,
JSON-encoded, and then base64-encoded, similar (but not identical) to
standard IDs. At the moment, they don't share exactly the same codepaths
to normal modules, but this could be adapted to be so in the future. We
also include a note of *what type* generated this ID - this is so we can
prevent type confusion.
Essentially, this enables a number of previously impossible use cases:
1. Returning a custom object from another module from a function
- This case is the simplest - we just extend our conversion that
unpacks all returned IDs from functions into their underlying types
(so while a module returns an XID, it can be queried as if it was X).
2. Accepting a custom object as a parameter to a function
- Because graphql doesn't support creating inline objects, we get
around this in the core api by instead passing IDs everywhere. All
the code-gen is setup to expect this, but module types weren't
IDable, so we failed during schema-checking.
Additionally, we need to transparently convert the ID from the
graphql request into the underlying storage data for the module.
3. Accepting a custom object from another module as a parameter to a
function
- This is the same case as above, but also involves ensuring that we
stitch in the type declarations from the module into our own schema
so that we have the right type.
However, here, we **don't** decode the ID into its underlying
data, it's a foreign type, so the module should only see the ID.
Signed-off-by: Justin Chadwell <[email protected]>
* disallow use of external module types in function+field signatures
While we now give all module objects ID-ability and enable a module to
accept its own objects as function inputs, we are not yet going to allow
modules to use objects from other (non-core) modules as function args,
function returns or object fields.
This is because allowing that results in a caller who depends on a given
module A to now not only have access to module A's types but also the
types of transitive dependencies. This in turn opens the doors to
dependency hell; if two versions of a given module show up multiple
times in the full dependency DAG we need some fairly complex dependency
resolution logic around which of those versions is exposed to the
caller.
That problem is famously difficult and while we may need to deal with it
someday, it's preferable to avoid it for as long as possible.
The idea is to instead add support for interfaces in follow ups, which
should unblock many of the use cases that call for interoperability
between different module types.
The main changes in this commit are to detect when a user tries to do
this and give them a descriptive error message in that case. Other
related changes are:
* an additional integ test case for the situation where there's
conflicting versions of a give module in the transitive dependency
DAG, which is expected to continue working.
* tracking of which module a given schema type was loaded from, which
allows us to distinguish between use of a type from core (which is
still allowed) and a type from a dependency module.
* removal of "Dependencies" from the ExecutableSchema interface we use
internally, which overlapped with some of the other changes here and
was completely unused (leftover from ancient days during the Cloak
project).
Signed-off-by: Erik Sipsma <[email protected]>
* check expected module type name direct in decode
Signed-off-by: Erik Sipsma <[email protected]>
---------
Signed-off-by: Justin Chadwell <[email protected]>
Signed-off-by: Erik Sipsma <[email protected]>
Co-authored-by: Erik Sipsma <[email protected]>
This feature allows all module declared objects to be converted to a respective ID-type using the "id" field, and converted from an ID-type using the "loadFromID" helper. This effectively makes these types fully idable.
IDs are essentially the contents of the module type's data, JSON-encoded, and then base64-encoded, similar (but not identical) to standard IDs. At the moment, they don't share exactly the same codepaths to normal modules, but this could be adapted to be so in the future. We also include a note of what type generated this ID - this is so we can prevent type confusion.
Essentially, this enables a number of previously impossible use cases:
Returning a custom object from another module from a function
Accepting a custom object as a parameter to a function
Because graphql doesn't support creating inline objects, we get around this in the core api by instead passing IDs everywhere. All the code-gen is setup to expect this, but module types weren't IDable, so we failed during schema-checking.
Additionally, we need to transparently convert the ID from the graphql request into the underlying storage data for the module.
Accepting a custom object from another module as a parameter to a function
This is the same case as above, but also involves ensuring that we stitch in the type declarations from the module into our own schema so that we have the right type.
However, here, we don't decode the ID into its underlying data, it's a foreign type, so the module should only see the ID.
So, I'm not actually sure about the actual method by which this encodes the module data into the ID - I think this is the right approach? It's pretty much the easiest way to store the state, but we could also randomly assign IDs and simply cache the results (potentially useful if the IDs start getting really long), or we could do something similar to the core API and just store the parents (though I'm not 100% sure how this would work, I think this might be the thing that needs IDs v2?).