How to use graphql-request - 10 common examples

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 startups-services / epic-admin-dashboard / pages / api / exec.js View on Github external
export default async function exec(req, res) {
  try {
    const graphQLClient = new GraphQLClient(process.env.graphcms_endpoint, {
      headers: {
        authorization: `Bearer ${process.env.graphcms_pat}`,
      },
      method: 'POST',
    });
    const result = await graphQLClient.request(req.body.query, req.body.variables);
    return res.status(200).send(result);
  } catch (e) {
    // eslint-disable-next-line no-console
    console.error(e);
    return res.status(502).send('bad request');
  }
}
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 patcito / nextjob / pages / index.js View on Github external
// select distinct(locality), country, location from "Job"
    // select
    //       ST_Distance_Sphere(location::Geometry, ST_MakePoint(48.857091,
    //                   2.353702)) as distance
    //                    from
    //                        "Job"
    //                        create or replace function search_job_distance(lat float,long float)
    //                          returns table (distance float)
    //                          as
    //                          $body$
    //                          select ST_Distance_Sphere(location::Geometry, ST_MakePoint(lat,
    //                                     long)) as distance from  "Job"
    //
    //                                     $body$
    //                                     language sql;
    const client = new grequest.GraphQLClient(getJobsopts.uri, {
      headers: getJobsopts.headers,
    });
    let jobsAndCompanies = await client
      .request(getJobsopts.query, {
        ownerId: userId,
        userId: userInfo.userId,
        meId: meId,
        companyId: companyId,
        skill: skill,
        description: description,
        description_fr: description,
        remote: remote,
        employementType: employementType,
        country: country,
        locality: locality,
        nocompany: query.companies ? null : '_no_company_',
github Human-Connection / Human-Connection / backend / src / schema / resolvers / user_management.spec.js View on Github external
beforeEach(async () => {
    const adminParams = {
      role: 'admin',
      email: 'admin@example.org',
      password: '1234',
    }
    // create an admin user who has enough permissions to create other users
    await factory.create('User', adminParams)
    const headers = await login(adminParams)
    authenticatedClient = new GraphQLClient(host, { headers })
    // but also create an unauthenticated client to issue the `User` query
    client = new GraphQLClient(host)
  })
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 TimothyCole / timcole.me / frontend / graphql-client.js View on Github external
import { GraphQLClient } from 'graphql-request';
const _TWITCH_CLIENT_ID = "kimne78kx3ncx6brgo4mv6wki5h1ko";

const client = new GraphQLClient('https://gql.twitch.tv/gql', {
	headers: {
		"Client-ID": _TWITCH_CLIENT_ID
	},
})

module.exports = function () {
	return {
		graphql(query) { return client.request(query); }
	}
}
github patcito / nextjob / pages / applications.js View on Github external
if (rm) {
      const acceptApplicationopts = {
        uri: getHasuraHost(process, undefined, publicRuntimeConfig),
        json: true,
        query: updateJobApplicationStatus.loc.source.body,
        headers: {
          'x-access-token': Cookies.get('token'),
          'x-access-role': 'userType',
        },
      };
      let vars = {
        id: jobApplication.id,
        status: true,
      };

      const client = new grequest.GraphQLClient(acceptApplicationopts.uri, {
        headers: acceptApplicationopts.headers,
      });

      client.request(acceptApplicationopts.query, vars).then(gdata => {
        this.handleUpdateCallback(
          this.i18n.t(
            'applications:This application has been accepted successfully',
          ),
        );
      });
    }
  };

graphql-request

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

MIT
Latest version published 11 months ago

Package Health Score

88 / 100
Full package analysis