Reddit – Dive into anything
how are you? I’m having several problems in my code haha and I don’t understand why. I’m using GraphQL in React Native, but it doesn’t have much to do with the fact that I’m using RN.When I want to make a request to an endpoint that I want, it throws me the error [TypeError: Network request failed], but only in the function that I want, I tried with some examples, and it responds correctly
I leave 3 functions and the output in the terminal:
const fetchh = async () => {
await fetch('https://api.thegraph.com/subgraphs/name/ensdomains/ens', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
query: `
query ($name: String!)
{
domains(first: 75, where: {name_contains: $name, resolvedAddress_not: null, name_ends_with: ".eth"}) {
name
}
}
`,
variables: {
name: 'asd',
},
}),
})
.then(res => res.json())
.then(result => console.log(result, 'RESULTADO'))
.catch(err => console.log(JSON.stringify(err), 'ERROR FETCH1'));
};
/////////
const fetch2 = async () => {
fetch('https://www.learnwithjason.dev/graphql', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
query: `
query GetLearnWithJasonEpisodes($now: DateTime!) {
allEpisode(limit: 10, sort: {date: ASC}, where: {date: {gte: $now}}) {
date
title
guest {
name
twitter
}
description
}
}
`,
variables: {
now: new Date().toISOString(),
},
}),
})
.then(res => res.json())
.then(result => console.log(result, 'FETCH 2'));
};
///////
const fetch3 = async () => {
fetch('https://api.thegraph.com/subgraphs/name/ensdomains/ens', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
query: `query ($address: ID!)
{
accounts(where: {id: $address}, first: 1000) {
registrations {
domain {
name
subdomains {
name
}
}
expiryDate
}
}
}`,
variables: {
address: '0x983110309620D911731Ac0932219af06091b6744'.toLowerCase(),
},
}),
})
.then(res => res.json())
.then(result => console.log(result))
.catch(err => console.log(err, 'ERROR FETCH 3'));
};
////////
LOG [TypeError: Network request failed] ERROR FETCH 3
LOG {"line":25338,"column":33,"sourceURL":"localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.welookapp&modulesOnly=false&runModule=true"} ERROR FETCH1
LOG {"data": {"allEpisode": [[Object], [Object], [Object], [Object], [Object], [Object]]}} FETCH 2
//////
The error FETCH 1 and FETCH 3 are the same except for FETCH1 I put JSON.stringify in the .catchIt can also be seen that FETCH 2 brought the results correctly, do you know what could be happening?