Skip to content

Instantly share code, notes, and snippets.

@nksaraf
nksaraf / graphql-fetch.ts
Last active October 3, 2022 20:08
React Query with GraphQL
// Taken mostly from prisma-labs/graphql-request
import "isomorphic-unfetch";
import { print } from "graphql/language/printer";
import { DocumentNode } from "graphql";
export type Variables = { [key: string]: any };
export interface Headers {
[key: string]: string;
}
// AUTO-GENERATED
import {
NameNode,
DocumentNode,
OperationDefinitionNode,
VariableDefinitionNode,
VariableNode,
SelectionSetNode,
FieldNode,
@nksaraf
nksaraf / rollup-typescript.md
Created August 7, 2020 17:54 — forked from aleclarson/rollup-typescript.md
The best Rollup config for TypeScript libraries

Features

🔥 Blazing fast builds
😇 CommonJS bundle
🌲 .mjs bundle
.d.ts bundle
🧐 Source maps

Install

@nksaraf
nksaraf / graphiql.html
Last active December 10, 2020 01:02
GraphiQL with Explorer for servers
<!DOCTYPE html>
<html>
<head>
<style>
body {
height: 100vh;
margin: 0;
width: 100vw;
overflow: hidden;
}
@nksaraf
nksaraf / atomic-recoil.tsx
Last active January 12, 2021 15:34
jotai-like API for recoil
import {
selector,
atom as recoilAtom,
useRecoilState,
useSetRecoilState,
AtomEffect,
RecoilState,
} from "recoil";
import type {
@nksaraf
nksaraf / index.esm.js
Last active December 14, 2020 00:36
preact-react
export { default } from 'preact/compat'
export * from 'preact/compat'
@nksaraf
nksaraf / index.d.ts
Last active December 14, 2020 05:51
magiql-ide
interface Options {
uri: string;
cdn?: string;
version?: string;
}
export declare function renderGraphiQL(props: Options): string;
export default function renderGraphiQL(props: Options): string;
const shellac = require('shellac').default;
shellac`
$$ node scripts.js ${process.argv.slice(1).join(' ')}
`
@nksaraf
nksaraf / distilt.ts
Last active December 29, 2020 13:47
distilt.js
#!/usr/bin/env node
const { existsSync, promises: fs } = require('fs')
const path = require('path')
if (require.main === module) {
main().catch((error) => {
console.error(error)
process.exit(1)
})
@nksaraf
nksaraf / error.ts
Last active December 29, 2020 23:33
fetchGraphQL.ts
/**
* Shamelessly copied from the amazing `urql` client
* https://github.com/FormidableLabs/urql/blob/main/packages/core/src/utils/error.ts
*/
import { GraphQLError } from "graphql/error/GraphQLError";
const generateErrorMessage = (
networkErr?: Error,
graphQlErrs?: GraphQLError[]