-
Notifications
You must be signed in to change notification settings - Fork 67
enhancement: generate GraphQL schema from JSON ABI #1396
Conversation
7eb0ea3
to
d052e53
Compare
142ae7e
to
9e46ac2
Compare
294d8a9
to
d20f959
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Left some feedback
- Mainly about restructuring this a bit, and using
fuel_indexer_macro_utils
@@ -21,6 +21,7 @@ | |||
- [Scalars](./designing-a-schema/scalars.md) | |||
- [Directives](./designing-a-schema/directives.md) | |||
- [Relationships](./designing-a-schema/relationships.md) | |||
- [Generating a Schema](./generating-a-schema/index.md) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should go int the Designing a schema
section maybe under a section called Automatic Schema Generation
(or something that makes it clear what this section is about).
@@ -0,0 +1,155 @@ | |||
# Automatically generating GraphQL schema from JSON ABI | |||
|
|||
`forc index new` supports automatically generating GraphQL schema from a contract JSON ABI. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- I think this has to be re-written.
- @lostman We spent weeks on the docs, combing through every single line making sure they read properly and that all examples are informative and work
- It sucked, it wasn't fun, but the docs are so much better now
- Let's keep this trend going with the docs in this PR.
- Ideally the docs should:
- Show me the tiniest Sway smart contract with various simple types (struct, enum, etc)
- Show me how to use
forc index new --json-abi
- Show me the resultant schema that gets produced from that command ☝🏼
- I think we have an example of this in the docs already here (again, I want to be very clear that I realize this is a PITA 😅 )
} | ||
|
||
/// Whether a `TypeDeclaration` is a unit type | ||
pub fn is_unit_type(typ: &TypeDeclaration) -> bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Ah ok, yea, as I mentioned in the "Is there any particular reason..." comment...
- All of this codegen logic needs to be moved to
fuel-indexer-macros
(we're duplicating a ton of logic here)
- All of this codegen logic needs to be moved to
So maybe something like:
fuel_indexer_macros::schema_gen
- This is where you put all the logic related to auto-creating this schema
- And you would just pull in
fuel_indexer_macros::helpers
instead of duplicating this stuff - We already have a
fuel_indexer_macro_utils
crate- This was previously being used for indexer-internal proc macros (as opposed to public macros)
- You could potentially move that
#[metrics]
macro out offuel_indexer_macro_utils
and intofuel_indexer_macros
(so now fuel_indexer_macros would export#[metrics]
and#[indexer
] - Then that would allow you to put your macro logic in
fuel_indexer_macro_utils
(after you make it a non-proc-macro crate) - Finally, this would allow you to import the macro functions into
forc_index::new
viause fuel_indexer_macro_utils::schema_gen::*
- I think this solves a lot of problems but let me know what you think
- And you would just pull in
- This is where you put all the logic related to auto-creating this schema
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The issue is that fuel-indexer-macros
is a proc-macro
crate and can only export macros.
So, fuel_indexer_macros::schema_gen
doesn't work.
we're duplicating a ton of logic here
Not duplicating. I moved the code from fuel_indexer_macros::helpers
.
Finally, this would allow you to import the macro functions into forc_index::new via use fuel_indexer_macro_utils::schema_gen::*
This is fine. I can move this logic there and make it non-proc-macro.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lostman I mentioned in my previous comment
Then that would allow you to put your macro logic in fuel_indexer_macro_utils (after you make it a non-proc-macro crate)
@@ -13,6 +13,7 @@ ARGS: | |||
OPTIONS: | |||
--absolute-paths Resolve indexer asset filepaths using absolute paths. | |||
-h, --help Print help information | |||
--json-abi <JSON_ABI> Path to JSON ABI for automatic schema generation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👌🏼
dd2806e
to
4012e5e
Compare
4012e5e
to
7bea7ec
Compare
Description
Closes #846.
This PR adds a
--json-abi
flag toforc index new
which facilitates automatic generation of the GraphQL schema from the given JSON ABI.Testing steps
Create a new indexer:
Copy the JSON ABI:
Set the
abi
in theManifest
Change
lib.rs
to refer to types from the generated schema:Verify that it builds:
Changelog
generate_schema()
, which generates a GraphQL schema from JSON ABI.packages/fuel-indexer-macros/src/helpers.rs
topackages/fuel-indexer-lib/src/helpers.rs
because they are now used in both places.