npm.io
1.2.1 • Published 3 years ago

@rayhanadev/replit-gql

Licence
MIT
Version
1.2.1
Deps
3
Size
611 kB
Vulns
0
Weekly
0
DeprecatedThis package is deprecated

Replit GraphQL

Reusable function to query Replit's GraphQL API. Written to consume @apollo/client with a patched node-fetch used by Replit.

It is recommended you add babel-plugin-import-graphql to your Babel configuration to import .graphql files. Otherwise you may use graphql-tag to the same effect.

For information on how to use the ApolloClient, visit its core API docs. Note, this package uses the core ApolloClient, not the React view layer.

Usage

import { GraphQL } from '@rayhanadev/replit-gql';
import CurrentUser from './queries/CurrentUser.graphql';

// You can use a Replit Token
// (connect.sid) for authenticated
// queries.
const { REPLIT_TOKEN } = process.env;
const client = GraphQL(REPLIT_TOKEN);

const { data } = await client.query({
  query: CurrentUser,
});

console.log(data);

Output:

{
  "currentUser": {
    "id": 4045907
  }
}