Skip to content
This repository has been archived by the owner on Oct 25, 2024. It is now read-only.

Commit

Permalink
tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
lostman committed Oct 18, 2023
1 parent 5d43dcb commit d20f959
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 43 deletions.
86 changes: 50 additions & 36 deletions docs/src/generating-a-schema/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ pub enum SimpleEnum {
Will be translated to GraphQL as:

```GraphQL
enum SimpleEnumEntity {
ONE
TWO
THREE
enum SimpleEnum {
One
Two
Three
}
```

Expand All @@ -56,59 +56,69 @@ forc index new --json-abi ./packages/fuel-indexer-tests/trybuild/abi/DAO-contrac
We get the following schema:

```GraphQL
enum CreationErrorEntity {
DURATIONCANNOTBEZERO
INVALIDACCEPTANCEPERCENTAGE
}
enum InitializationErrorEntity {
CANNOTREINITIALIZE
CONTRACTNOTINITIALIZED
}
enum ProposalErrorEntity {
INSUFFICIENTAPPROVALS
PROPOSALEXECUTED
PROPOSALEXPIRED
PROPOSALSTILLACTIVE
}
enum UserErrorEntity {
AMOUNTCANNOTBEZERO
INCORRECTASSETSENT
INSUFFICIENTBALANCE
INVALIDID
VOTEAMOUNTCANNOTBEZERO
}
type CallDataEntity {
enum CreationError {
DurationCannotBeZero
InvalidAcceptancePercentage
}

enum InitializationError {
CannotReinitialize
ContractNotInitialized
}

enum ProposalError {
InsufficientApprovals
ProposalExecuted
ProposalExpired
ProposalStillActive
}

enum UserError {
AmountCannotBeZero
IncorrectAssetSent
InsufficientBalance
InvalidId
VoteAmountCannotBeZero
}

type CallDataEntity @entity {
id: ID!
arguments: U64!
function_selector: U64!
}
type CreateProposalEventEntity {

type CreateProposalEventEntity @entity {
id: ID!
proposal_info: ProposalInfoEntity!
}
type DepositEventEntity {

type DepositEventEntity @entity {
id: ID!
amount: U64!
user: Identity!
}
type ExecuteEventEntity {

type ExecuteEventEntity @entity {
id: ID!
acceptance_percentage: U64!
user: Identity!
}
type InitializeEventEntity {

type InitializeEventEntity @entity {
id: ID!
author: Identity!
token: ContractId!
}
type ProposalEntity {

type ProposalEntity @entity {
id: ID!
amount: U64!
asset: ContractId!
call_data: CallDataEntity!
gas: U64!
}
type ProposalInfoEntity {

type ProposalInfoEntity @entity {
id: ID!
acceptance_percentage: U64!
author: Identity!
Expand All @@ -118,22 +128,26 @@ type ProposalInfoEntity {
proposal_transaction: ProposalEntity!
yes_votes: U64!
}
type UnlockVotesEventEntity {

type UnlockVotesEventEntity @entity {
id: ID!
user: Identity!
vote_amount: U64!
}
type VoteEventEntity {

type VoteEventEntity @entity {
id: ID!
user: Identity!
vote_amount: U64!
}
type VotesEntity {

type VotesEntity @entity {
id: ID!
no_votes: U64!
yes_votes: U64!
}
type WithdrawEventEntity {

type WithdrawEventEntity @entity {
id: ID!
amount: U64!
user: Identity!
Expand Down
14 changes: 7 additions & 7 deletions packages/fuel-indexer-lib/src/graphql/schema_gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ use std::collections::HashMap;
// can be converted to GraphQL:
//
// enum SimpleEnumEntity {
// ONE
// TWO
// THREE
// One
// Two
// Three
// }
fn decode_enum(types: &[TypeDeclaration], ty: &TypeDeclaration) -> Option<String> {
let name = ty.type_field.strip_prefix("enum ").unwrap();
Expand All @@ -31,7 +31,7 @@ fn decode_enum(types: &[TypeDeclaration], ty: &TypeDeclaration) -> Option<String
for c in components {
let ty = &types.get(c.type_id)?;
if is_unit_type(ty) {
fields.push(c.name.to_uppercase().to_string());
fields.push(c.name.to_string());
} else {
return None;
}
Expand All @@ -44,7 +44,7 @@ fn decode_enum(types: &[TypeDeclaration], ty: &TypeDeclaration) -> Option<String
.collect::<Vec<String>>()
.join("\n");

let output = format!("enum {name}Entity {{\n{fields}\n}}");
let output = format!("enum {name} {{\n{fields}\n}}");

Some(output)
}
Expand Down Expand Up @@ -98,7 +98,7 @@ fn decode_struct(
.collect::<Vec<String>>()
.join("\n");

let output = format!("type {name}Entity {{\n{fields}\n}}");
let output = format!("type {name}Entity @entity {{\n{fields}\n}}");

Some(output)
}
Expand Down Expand Up @@ -144,5 +144,5 @@ pub fn generate_schema(json_abi: &std::path::Path) -> Option<String> {
}
}

Some(output.join("\n"))
Some(output.join("\n\n"))
}

0 comments on commit d20f959

Please sign in to comment.