Eiffelbear
Eiffelbear

Reputation: 428

`No value provided for required argument: id` error in graph ql database

Question

import request

timestamp = 1607904000

graphql_endpoint = 'https://api.thegraph.com/subgraphs/name/perpetual-protocol/perp-position-subgraph'
headers = {"Content-Type": "application/json"}

fundingRateUpdatedEvent_query = """query {
                            fundingRateUpdatedEvent(first: 1000, orderBy:timestamp,orderDirection:asc, where:{timestamp_gt: %i}) {
                                    id
                                    amm
                                    rate
                                    underlyingPrice
                                    timestamp
                        }}""" % (timestamp)

request_result = requests.post(graphql_endpoint, json={'query': fundingRateUpdatedEvent_query}, headers=headers)
if request_result.status_code == 200:
    request_result.json()['data']['fundingRateUpdatedEvents']
else:
    raise Exception(f"GraphQL query failed to run by returning code of {request.status_code}.")
timestamp = 1607904000

graphql_endpoint = 'https://api.thegraph.com/subgraphs/name/perpetual-protocol/perp-position-subgraph'
headers = {"Content-Type": "application/json"}

positionChanged_query = """query {
                            positionChangedEvents(first: 1000, orderBy:timestamp,orderDirection:asc, where:{timestamp_gt: %i}) {
                                    id
                                    trader
                                    timestamp
                                    amm
                                    margin
                                    positionNotional
                                    exchangedPositionSize
                                    fee
                                    positionSizeAfter
                                    realizedPnl
                                    unrealizedPnlAfter
                                    badDebt
                                    liquidationPenalty
                                    spotPrice
                                    fundingPayment
                        }}""" % (timestamp)

request_result = requests.post(graphql_endpoint, json={'query': positionChanged_query}, headers=headers)
print(request_result)
if request_result.status_code == 200:
    print(request_result.json())
    request_result.json()['data']['positionChangedEvents']
else:
    raise Exception(f"GraphQL query failed to run by returning code of {request.status_code}.")

Upvotes: 0

Views: 1986

Answers (1)

Dan Paquin
Dan Paquin

Reputation: 29

You need to pluralize the entity you are querying:

fundingRateUpdatedEvents

I believe we encountered the same issue using the graph!

Upvotes: 2

Related Questions