Mirror: The small sibling of the graphql package, slimmed down for client-side libraries.

(chore) - introduce size check (#1)

* Switch to graphql@16 alpha

* prepare size check

* add command

* only compare vendor

* formatting

* convert to preact

Co-authored-by: Phil Pluckthun <phil@kitten.sh>

+45
.github/workflows/size.yml
···
···
+
name: compressed-size
+
on:
+
pull_request:
+
branches:
+
- main
+
+
jobs:
+
build:
+
runs-on: ubuntu-latest
+
steps:
+
- uses: actions/checkout@v2
+
+
- name: Setup Node
+
uses: actions/setup-node@v1
+
with:
+
node-version: '14'
+
+
- name: Get Yarn cache directory
+
id: yarn-cache-dir-path
+
run: echo "::set-output name=dir::$(yarn cache dir)"
+
+
- name: Use Yarn cache
+
uses: actions/cache@v2
+
id: yarn-cache
+
with:
+
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
+
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
+
restore-keys: |
+
${{ runner.os }}-yarn-
+
+
- name: Install Dependencies
+
if: |
+
steps.yarn-cache.outputs.cache-hit != 'true' ||
+
steps.node-modules-cache.outputs.cache-hit != 'true'
+
run: yarn install --prefer-offline --frozen-lockfile --non-interactive --silent
+
+
- name: Build GraphQL-Web-Lite
+
run: yarn build
+
+
- name: compressed-size-action
+
uses: preactjs/compressed-size-action@v2
+
with:
+
pattern: '{demo/dist-graphql/assets/vendor.*.js,demo/dist-lite/assets/vendor.*.js}'
+
build-script: size-check
+
repo-token: '${{ secrets.GITHUB_TOKEN }}'
+3
.gitignore
···
coverage/
/cypress/videos/**
/cypress/screenshots/**
···
coverage/
/cypress/videos/**
/cypress/screenshots/**
+
demo/yarn.lock
+
demo/dist-graphql
+
demo/dist-lite
+12
demo/index.html
···
···
+
<!DOCTYPE html>
+
<html lang="en">
+
<head>
+
<meta charset="UTF-8">
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
+
<title>test</title>
+
</head>
+
<body>
+
<div id="root"></div>
+
<script type="module" src="/src/index.jsx"></script>
+
</body>
+
</html>
+19
demo/package.json
···
···
+
{
+
"name": "demo",
+
"version": "0.0.0",
+
"private": true,
+
"scripts": {
+
"build": "yarn build:graphql && yarn build:lite",
+
"build:graphql": "vite build",
+
"build:lite": "vite build -c ./vite.alias.config.js"
+
},
+
"dependencies": {
+
"graphql": "^16.0.0-alpha.5",
+
"preact": "^10.5.14",
+
"@urql/preact": "^2.0.2"
+
},
+
"devDependencies": {
+
"@preact/preset-vite": "^2.1.0",
+
"vite": "^2.2.4"
+
}
+
}
+34
demo/src/Pokemons.jsx
···
···
+
import { gql, useQuery } from '@urql/preact';
+
+
const POKEMONS_QUERY = gql`
+
query Pokemons {
+
pokemons(limit: 10) {
+
id
+
name
+
}
+
}
+
`;
+
+
const Pokemons = () => {
+
const [result] = useQuery({ query: POKEMONS_QUERY });
+
+
const { data, fetching, error } = result;
+
+
return (
+
<div>
+
{fetching && <p>Loading...</p>}
+
+
{error && <p>Oh no... {error.message}</p>}
+
+
{data && (
+
<ul>
+
{data.pokemons.map(pokemon => (
+
<li key={pokemon.id}>{pokemon.name}</li>
+
))}
+
</ul>
+
)}
+
</div>
+
);
+
};
+
+
export default PokemonList;
+15
demo/src/index.jsx
···
···
+
import { render } from 'preact';
+
import Pokemons from './Pokemons';
+
+
const client = createClient({
+
url: 'https://trygql.formidable.dev/graphql/basic-pokedex',
+
});
+
+
render(
+
<React.StrictMode>
+
<Provider value={client}>
+
<Pokemons />
+
</Provider>
+
</React.StrictMode>,
+
document.getElementById('root')
+
);
+15
demo/vite.alias.config.js
···
···
+
import { defineConfig } from 'vite';
+
import path from 'path';
+
import preact from "@preact/preset-vite";
+
+
export default defineConfig({
+
plugins: [preact()],
+
resolve: {
+
alias: {
+
graphql: path.resolve('..', './dist')
+
}
+
},
+
build: {
+
outDir: './dist-lite'
+
}
+
});
+9
demo/vite.config.js
···
···
+
import { defineConfig } from 'vite';
+
import preact from "@preact/preset-vite";
+
+
export default defineConfig({
+
plugins: [preact()],
+
build: {
+
outDir: './dist-graphql'
+
}
+
});
+2 -1
package.json
···
"main": "index.js",
"license": "MIT",
"scripts": {
-
"build": "rollup -c scripts/rollup/config.js"
},
"homepage": "https://github.com/kitten/graphql-web-lite",
"bugs": {
···
"main": "index.js",
"license": "MIT",
"scripts": {
+
"build": "rollup -c scripts/rollup/config.js",
+
"size-check": "cd demo && yarn && yarn build"
},
"homepage": "https://github.com/kitten/graphql-web-lite",
"bugs": {