How to use the graphql-request.request function in graphql-request

To help you get started, we’ve selected a few graphql-request examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github brentvatne / hackernews-react-native-apollo / webtasks / votes / index.js View on Github external
module.exports = async (req, res) => {
  let queryResponse = await request(GRAPHCOOL_ENDPOINT, recentLinksQuery);
  if (queryResponse.error) {
    throw new Error('Error fetching links');
  }

  let linksWithScores = calculateScores(queryResponse.allLinks);
  let mutationQuery = generateMutation(linksWithScores);
  let mutationResponse = await request(GRAPHCOOL_ENDPOINT, mutationQuery);
  if (mutationResponse.error) {
    throw new Error('Error updating links');
  }

  console.log('Updated scores:');
  console.log(linksWithScores);

  if (req.body) {
    // Don't modify the vote record
    const event = await json(req);
    return event.data;
  } else {
    return {};
  }
};
github SaraVieira / awesome-talks / add-duration / index.js View on Github external
//             id: id,
    //             duration: youtube.duration,
    //             year: youtube.year,
    //             likes: youtube.likes,
    //             views: youtube.views
    //         })
    //     } catch (e) {
    //         console.log(e)
    //     }
    // })
    const js = await json(req)
    const video = js.data.Videos.node
    try {
        const youtube = await getYoutube(video.link)
        try {
            const update = await request(endpoint, updateDuration, {
                id: video.id,
                duration: youtube.duration,
                year: youtube.year
            })
            console.log(update)
        } catch (e) {
            console.log(e)
        }
    } catch (e) {
        console.log(e)
    }
    return null
}
github coderplanets / coderplanets_admin / pages / communities / tags.js View on Github external
static async getInitialProps({ req, asPath }) {
    const isServer = !!req
    if (!isServer) return {}

    const data = await request(GRAPHQL_ENDPOINT, schema.pagedTagsRaw, {
      filter: queryStringToJSON(asPath),
      /* filter: mergeRouteQuery(query), */
      /* filter: { page: 2, size: 20 }, */
    })

    /* eslint-disable */
    const { locale, messages } = req || Global.__NEXT_DATA__.props
    /* eslint-enable */
    const langSetup = {}
    langSetup[locale] = messages

    return {
      langSetup,
      /* communities: data.pagedCommunities, */
      communitiesContent: { pagedTags: data.pagedTags },
    }
github prisma-archive / graphcool-templates / outdated / file-handling / file-proxy / extension-file-proxy.js View on Github external
// The File API has created a File node. We need to update the URL to
        // point to our own endpoint. Unfortunately, we can't, so we use a new
        // field on the File Type to store our URL.
        const query = `
          mutation updateFile($id: ID!, $newUrl: String!) {
            updateFile (id: $id, newUrl: $newUrl)
            { name size newUrl id contentType }
          }`;

        const variables = {
          id: result.id,
          newUrl: result.url.replace('files.graph.cool', `${req.headers.host}/${webtaskName}`)
        };

        gqlrequest(graphCoolSimpleEndpoint, query, variables)
          .then(data => res.status(200).send(data.updateFile));
      });
    });
github Human-Connection / Human-Connection / backend / src / schema / resolvers / user_management.spec.js View on Github external
it('responds with "Your account has been disabled."', async () => {
        await disable('acb2d923-f3af-479e-9f00-61b12e864666')
        await expect(
          request(
            host,
            mutation({
              email: 'test@example.org',
              password: '1234',
            }),
          ),
        ).rejects.toThrow('Your account has been disabled.')
      })
    })
github 3box / 3box-js / src / api.js View on Github external
static async profileGraphQL (query, opts = {}) {
    opts = Object.assign({ graphqlServer: GRAPHQL_SERVER_URL }, opts)
    return graphQLRequest(opts.graphqlServer, query)
  }
github steedos / object-server / packages / report / reporter.js View on Github external
async getData(report) {
    if (report.graphql){
      let dataResult = await request("http://localhost:3600/graphql/default/", report.graphql);
      let items = dataResult[`${report.object_name}`];
      if (items && items.length) {
        let processChildren = (item, parentKey, object) => {
          /**
            把{
              "object_name": [{
                "_id": "R9HquKmR5fHbDqdWq",
                "name": "测试1",
                "organization": {
                  "_id": "P7XMJMjKoSz4yaK49",
                  "name": "组织A"
                }
              }]
            }
            中的organization转成 "organization._id", "organization.name",
            转换后结果: {
github frostiq / makerdao-superdashboard / dashboard.js View on Github external
function requestCupActions() {
	const query = `{
	  getCup(id: 1118) {
	    actions {
	      nodes {
	      	time
	      	ratio
	      }
	    }
	  }
	}
	`

	request('https://graphql.makerdao.com/v1', query).then(data => showDataInformation(data))
}
github BigMaster / graphql-dataloader / src / lib / GraphQLDataLoader.js View on Github external
originalRequest(query, variables = {}) {
    return request(this.endpoint, query, variables);
  }
github BigMaster / graphql-dataloader / src / lib / GraphQLDataLoader.js View on Github external
directives: [],
      kind: "OperationDefinition",
      operation: "query",
      selectionSet: {
        kind: "SelectionSet",
        selections: querySelections,
      },
      variableDefinitions,
    }];

    const query = print({
      kind: "Document",
      definitions: [...queryDefinition, ...otherDefinitions]
    });

    return GraphQLDataLoader.dispatchResult(await request(this.endpoint, query, newVariables), separator);
  }

graphql-request

Minimal GraphQL client supporting Node and browsers for scripts or simple apps.

MIT
Latest version published 20 days ago

Package Health Score

91 / 100
Full package analysis