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

feat: add support for variables in subgraphRequest function #1047

Merged
merged 4 commits into from
Aug 21, 2024

Conversation

wa0x6e
Copy link
Contributor

@wa0x6e wa0x6e commented Aug 20, 2024

This PR adds support for variable when sending graphql request via the subgraphRequest utils function.

Injecting variables via the options argument is very ugly, but in order to be backward compatible, this seems to be the only way.

How to test

import { VariableType } from 'json-to-graphql-query';

const result = await subgraphRequest(
    'https://hub.snapshot.org/graphql',
    {
      __variables: {
        id: 'String!'
      },
      space: {
        __args: {
          id: new VariableType('id')
        },
        id: true,
        name: true
      }
    },
    {
      variables: {
        id: 'aave.eth'
      }
    }
  );
  console.log(result);

It should print

{ space: { id: 'aave.eth', name: 'Aave' } }

@wa0x6e wa0x6e marked this pull request as ready for review August 20, 2024 15:44
@wa0x6e wa0x6e requested a review from ChaituVR August 20, 2024 15:44
@ChaituVR
Copy link
Member

Where do we want to use this?

@wa0x6e
Copy link
Contributor Author

wa0x6e commented Aug 20, 2024

In sequencer, in the delegate statement pr. Some graphql api does not work with the hardcoded variables inside the query, since they don't use string type, but enum

src/utils.ts Outdated Show resolved Hide resolved
Copy link
Member

@ChaituVR ChaituVR left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tAck

@ChaituVR ChaituVR merged commit 901305a into master Aug 21, 2024
4 checks passed
@ChaituVR ChaituVR deleted the feat-support-variables-in-subgraphRequest branch August 21, 2024 08:16
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

Successfully merging this pull request may close these issues.

2 participants