Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto-Generate Interfaces #429

Open
dOrgJelli opened this issue Mar 9, 2020 · 0 comments
Open

Auto-Generate Interfaces #429

dOrgJelli opened this issue Mar 9, 2020 · 0 comments
Assignees

Comments

@dOrgJelli
Copy link
Contributor

  • I think the biggest problem w/ the client library is its maintainability. As the subgraph schema changes (new properties, name changes, entity connections / edges), the client library has to be manually updated to reflect all of these changes. I propose that we auto-generate as much as we can. Here’s how.
    • The entity classes have 3 key pieces: Read, Write, Search
    • Read & Search can be generated
    • Write will be hand authored
    • I’d also love to lend a hand in writing this code generator, just holler :) I don’t think it’d take that long to implement (1-2 weeks), since GraphQL AST parsing libraries exist.
    • Here’s a code sample (2 pages):

Subgraph Schema (Hand Authored):

type DAO @entity {
 id: ID!
 address: Bytes! @map(type: "Address")
 name: String!
 nativeToken: Token!
 proposals: [Proposal!] @derivedFrom(field: "dao")
 ...
}

State + Search (Auto-Generated):

interface IDAOState {
 id: ID,
 address: Address,
 name: String,
 nativeToken: EntityRef<Token>
}
 
interface IDAOQueryFilter extends ICommonQueryOptions {
 where?: {
   id?: ID,
   address?: Address,
   name?: string,
   nativeToken?: ID,
   [key: string]: any
 }
}
 
class DAOState implements IStateful<IDAOState> {
 public id: ID
 
 constructor(public context: Arc, idOrState: ID | IDAOState) {
   if (typeof idOrState === 'string') {
     this.id = idOrOpts.toLowerCase()
   } else {
     this.id = idOrState.id
     this.setState(idOrState)
   }
 }
 
 public state(options: IQueryOptions) {
   // query all fields...
 }
 
 public search(
   context: Arc,
   filter: IDAOQueryFilter = { },
   options: IQueryOptions = { }
 ) {
   // build the 'where' filter & query...
 }
 
 public proposals(
   filter: IProposalQueryFilter = { },
   options: IQueryOptions
 ) {
   if (!options.where) {
     options.where = {}
   }
   options.where.dao = this.id
   return Proposal.search(this.context, filter, options)
 }
}

Write (Hand Authored)

class DAO extends DAOState {
 public createProposal(...) {
   // hand authored
 }
}
@dOrgJelli dOrgJelli added this to the Arc 2.0 Phase 3 milestone Mar 9, 2020
@dOrgJelli dOrgJelli self-assigned this Mar 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant