Closed ZimboPro closed 4 months ago
Our error messages could use some work π Thanks for powering through it.
All names in Trustfall schemas and queries are case-sensitive. This error intends to say that your query starts with { resource
(meaning that it looks for an entry point called resource
) but no such entry point exists β based on your resolve_starting_vertices()
implementation it seems like it might be called Resource
instead. Try capitalizing it in your query and the error should hopefully go away?
I'd love to hear about your work on the custom linter you're building β it sounds very cool!
I just realised the issue, because I was copying and pasting, I used the OpenAPI schema :rofl:
So the issue should be updated to, if I don't have a schema, how do I execute the query?
Is it even possible to represent JSON in a GraphQL schema?
The linter is to check Terraform config files and OpenAPI docs to ensure that is correctly set up and the cross file type config is correct. I might extend it to Python as well if using FastAPI.
[EDIT] typos
The linter is to check Terraform config files and OpenAPI docs to ensure that is correctly set up and the cross file type config is correct. I might extend it to Python as well if using FastAPI.
Oooh this sounds very cool! I'd love to learn more β might you be up for a virtual coffee chat sometime next week?
Is it even possible to represent JSON in a GraphQL schema?
In principle, yes. In fact, in principle it's always possible to write a schema for any data source β even if it's just raw binary data. But depending on your exact use case, that schema might not be useful, ergonomic, sufficiently expressive, etc.
For example, here's one valid way to represent arbitrary JSON in a Trustfall schema:
type Json {
"""Contents of this JSON document, as a JSON serialized string."""
contents: String!
}
Here's another one:
type Json {
"""Contents of this JSON document, as a JSON serialized string."""
contents: String!
"""Any child elements contained inside this JSON document, in unspecified order."""
child_elements: [Json!]
}
Here's yet another one:
interface Json {
contents: String!
}
type JsonNumber implements Json {
contents: String!
value: Float!
}
type JsonString implements Json {
contents: String!
value: String!
}
type JsonArray implements Json {
contents: String!
values: [Json!]!
}
type JsonDict implements Json {
contents: String!
key_values: [JsonKeyValue!]
}
type JsonKeyValue {
key: Json
value: Json
}
There are infinitely more schemas that are all valid ways to represent JSON. But not all of them are good nor useful. Data modelling is hard, and writing high-quality Trustfall schemas is no different β it requires practice!
The best way to model your data is a function of how you intend to use it β what queries you need to run, which pieces of detail are crucial to expose vs safe to ignore, etc. So I usually recommend starting with the queries you want to run, setting up a minimal schema that would make those queries tidy and ergonomic, and then slowly working to expand that schema.
I wrote up a few more tips in a comment here.
Oooh this sounds very cool! I'd love to learn more β might you be up for a virtual coffee chat sometime next week? Definitely keen for a virtual coffee
Thanks for the advice, will talk to my team about what we want to query in the Terraform files
Closing ticket since it is not a bug but an implementation issue from my end
Thanks for the advice, will talk to my team about what we want to query in the Terraform files
Would love to hear what they say! Thanks!
They loved the tool, they just want it to be a bit more extensible since I am the only one with knowledge of Rust currently. So want to see if I can have the adapters load as WASM plugins to allow it to be a lot more flexible
Firstly, thank you so much for the library. I am really enjoying and what to introduce it as a custom linting tool at work (as well as Rust).
I have worked through the HN adapter and did manage to create a (somewhat limited) OpenAPI adapter. I am busy creating one for Terraform files. To make it easier, I am converting the files into the JSON equivalent. I used the BasicAdapter but when I query I get the following error
The referenced path does not exist in the schema: ["resource"]
I did get inspiration from https://github.com/felipesere/trustfall-serde-yaml for the implementation
The code for the adapter is:
The reason it accepts a Vec is because the Terraform files gets converted into JSON for each file, and not merged.
The query used was
The file used was
and the JSON equivalent is