graph-tooling icon indicating copy to clipboard operation
graph-tooling copied to clipboard

`graph codegen` doesn't export interfaces defined in the schema

Open cruzdanilo opened this issue 3 years ago • 7 comments

cruzdanilo avatar Feb 15 '22 15:02 cruzdanilo

hey @cruzdanilo - what are you looking to use the interfaces for?

azf20 avatar Feb 22 '22 11:02 azf20

@azf20 abstraction between multiple entities

cruzdanilo avatar Feb 22 '22 12:02 cruzdanilo

@cruzdanilo yes, but codegen is to facilitate writing handlers in Assemblyscript - I am familiar with using interfaces for GraphQL queries, but do you have an example (perhaps pseudocode) of what you are looking to do in Assemblyscript? Are you looking to fetch an entity that might be one of several types (with a shared interface)?

azf20 avatar Feb 22 '22 16:02 azf20

interface BaseEntity {
  id: ID!
  blockNumber: Int!
  contract: Bytes!
}

type Transfer implements BaseEntity @entity {
  id: ID!
  blockNumber: Int!
  contract: Bytes!
  from: Bytes!
  to: Bytes!
  tokenId: Int!
}
import { Bytes, ethereum } from '@graphprotocol/graph-ts';

interface BaseEntity { // this should be exported by codegen
  id: string;
  blockNumber: i32;
  contract: Bytes;
}

export default function applyMetadata<T extends BaseEntity>(entity: T, event: ethereum.Event): T {
  entity.blockNumber = event.block.number.toI32();
  entity.contract = event.address;
  return entity;
}

cruzdanilo avatar Feb 22 '22 17:02 cruzdanilo

Got it, thanks! @otaviopace seems like interfaces are excluded from codegen here: https://github.com/graphprotocol/graph-cli/blob/110c90c6c026d68ce3b77b60dff1337398cbf711/src/codegen/schema.js#L43 What do you think about including them to support the use case above?

azf20 avatar Feb 24 '22 12:02 azf20

I am also facing the same issue as I am trying to do abstraction between different similar metadata.

tonyfung99 avatar Dec 12 '22 10:12 tonyfung99

Faced the same issue now.

Until this is implemented, would you like to add a section Unsupported GraphQL Features in your docs, and mention that interfaces are not supported?

PaulRBerg avatar May 11 '25 07:05 PaulRBerg