-2

Given a GraphQL entity like this:

type Action @entity(immutable: true) {
  id: String!
  subgraphId: BigInt!
  block: BigInt!
  chainId: BigInt!
  from: Bytes!
  hash: Bytes!
  timestamp: BigInt!
  category: ActionCategory!
  contract: Bytes!
  fee: BigInt
  addressA: Bytes
  addressB: Bytes
  amountA: BigInt
  amountB: BigInt
}

I would like to auto-generate a fragment like this:

fragment ActionFragment on Action {
  id
  addressA
  addressB
  amountA
  amountB
  block
  category
  chainId
  contract
  from
  hash
  subgraphId
  timestamp
}

I know it's not hard to copy-paste the entity and then change it to a fragment, but we have many entities in our schema, and I would prefer an automated solution (if it exists). Maybe there is a tool/npm package that can do this?

2
  • What is ActionCategory, an other type? (I assume BigInt and Bytes are both scalars) Commented Jul 11 at 14:25
  • ActionCategory is an enum. And yes, BigInt and Bytes scalars. Commented Jul 11 at 14:30

1 Answer 1

0

I very much doubt such a tool exists, it goes against the spirit of GraphQL: you should only query what you need. You need to do that deliberately, and manually; especially when handling nested fields in a graph of entities you need to decide on the cut-off point. You cannot just query everything the schema provides.

If you really always want to query the entire Action (and force everyone to do that), make it a scalar Action instead of a type in your schema. I would not recommend that though as you loose the field typing.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.