-
Hello all, I'm really enjoying cue-lang so far but I've stumbled across a weird behavior that hangs any I have a type #Entity: {
name: string
fields: [string]: #Types | [...#Types]
storage: #Storage
ref: #Ref
}
_entity: [string]: #Entity
_entities: {
for k, x in _entity {
"\(k)": x & {
fields: {
for fk, s in x.storage.sql.fields {
"\(fk)": s.nitro_type
}
for fk, s in x.graphql {
"\(fk)": s
}
}
}
}
}
nitro: entities: _entities I've narrowed down the issue to be the conjunction ... rest of the file
_entities: {
for k, x in _entity {
"\(k)": { // <- NOTE HERE: I'm not using `x & {`
fields: {
for fk, s in x.storage.sql.fields {
"\(fk)": s.nitro_type
}
}
}
}
}
Then this works. Another interesting fact is that, if I remove the loop and keep the conjunction it also works, for example: _entities: {
for k, x in _entity {
"\(k)": x & {
fields: {
// no loop
}
}
}
} Below you can grab the entire Do you have any tips on how to debug this or if I'm doing something wrong? |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments
-
Hi @fenos - welcome to the CUE project! Please can you confirm what CUE version you are using? |
Beta Was this translation helpful? Give feedback.
-
I've been looking into this a bit. Here's a simpler version of the example. Running
|
Beta Was this translation helpful? Give feedback.
-
@fenos I'll leave @rogpeppe is digging into what is causing the "hang" here. But in the meantime, here is one suggestion for rewriting your CUE code, which has the added benefit if working around the bug! $ diff -wu before.txt after.txt
--- before.txt 2022-04-26 11:38:18.737383719 +0100
+++ after.txt 2022-04-26 11:37:57.300883136 +0100
@@ -15,9 +15,9 @@
is_null: bool | *false
default?: string
nitro_type: #Types
- ...
}
-#VarChar: #SQLField & {
+#VarChar: {
+ #SQLField
size: int | *255
nitro_type: #String
}
@@ -38,9 +38,9 @@
}]
type: string
}
- ...
}
-#String: #Scalar & {
+#String: {
+ #Scalar
go: {
type: "string"
} The resulting code is https://cuelang.org/play/?id=bcGIfbV1PW-#cue@export@cue, which you can see does evaluate even in the browser! The use of embedding here I think better reflects what you're trying to represent (but please let me know if I misunderstood) and has the added benefit that the closedness constraint on the embedded definition is relaxed for the purposes of embedding.
|
Beta Was this translation helpful? Give feedback.
-
@myitcv Thanks for the warm welcome! I love CUE! The version I'm using is:
Ahh!! The embedding is spot on!! it makes total sense to me! Thanks! @rogpeppe Thanks a lot for looking into this. Much appreciated your small snippet to reproduce the issue! |
Beta Was this translation helpful? Give feedback.
-
Thanks a lot again folks. This will unlock further development of an idea I have to declaratively build APIs 🎉 Hopefully, I'll be able to come up with a proper SDL as a superset of But overall I believe is doable! |
Beta Was this translation helpful? Give feedback.
@fenos I'll leave @rogpeppe is digging into what is causing the "hang" here.
But in the meantime, here is one suggestion for rewriting your CUE code, which has the added benefit if working around the bug!