Skip to content

Commit 114a66b

Browse files
authored
Merge pull request #526 from gadget-inc/feature/autoform
feature/autoform
2 parents 402e054 + 0876309 commit 114a66b

File tree

144 files changed

+29865
-1133
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

144 files changed

+29865
-1133
lines changed

.eslintrc.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@ module.exports = {
22
extends: "@gadgetinc/eslint-config",
33
parserOptions: {
44
tsconfigRootDir: __dirname,
5-
project: ["./packages/*/tsconfig.json", "./scripts/tsconfig.json", "./packages/blog-example/tsconfig.node.json"],
5+
project: [
6+
"./packages/*/tsconfig.json",
7+
"./packages/react/cypress/tsconfig.json",
8+
"./scripts/tsconfig.json",
9+
"./packages/blog-example/tsconfig.node.json",
10+
],
611
},
712
settings: {
813
"import/extensions": [".js", ".jsx"],

.github/workflows/test.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,17 @@ jobs:
1414
run: pnpm test
1515
- name: Build example package
1616
run: pnpm --filter=blog-example build-vite
17+
test-cypress:
18+
runs-on: ubuntu-latest
19+
steps:
20+
- uses: actions/checkout@v3
21+
- uses: ./.github/actions/setup-test-env
22+
- name: Build all packages (so they can require each other)
23+
run: pnpm build
24+
- name: Cypress info
25+
run: pnpm exec cypress info
26+
- name: Run cypress tests
27+
run: pnpm --filter=react exec cypress run --browser chrome --component --env JS_CLIENTS_TEST_API_KEY=${{secrets.CYPRESS_JS_CLIENTS_TEST_API_KEY}}
1728
lint:
1829
runs-on: ubuntu-latest
1930
steps:

.gitignore

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,11 @@ packages/*/dist
1414
packages/sample-app
1515
*.orig
1616
cypress.env.json
17-
packages/shopify-extensions/react
17+
packages/shopify-extensions/react
18+
# generated graphql queries
19+
packages/react/src/internal/gql
20+
21+
#generate package.json to make submodules lookup work
22+
packages/react/auto
23+
24+
*storybook.log

Contributing.md

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,45 @@
1-
# Development environment
1+
# Contributing
22

3-
We require `node` and `pnpm` to exist. If you're a nix user, we have a flake.nix present that installs the same version of the development tools we use for everyone.
3+
## Development environment
44

5-
# Building TypeScript
5+
We require `node` and `pnpm` to exist. If you're a nix user, we have a `flake.nix` present that installs the same version of the development tools we use for everyone.
6+
7+
## Building TypeScript
68

79
- You can run `pnpm build` to build all the projects in the repo
810
- You can run `pnpm watch` to start the TypeScript watcher process for all the projects in the repo which will recompile files as you change them
911

10-
# Prereleasing
12+
## Running Cypress tests
13+
14+
For running the Cypress tests, you need an API key for communicating with a Gadget app this repo uses for testing. You can ask a Gadget staff member for an existing key, or fork the test app and use your own API key for [this app](https://app.gadget.dev/auth/fork?domain=js-clients-test--development.gadget.app).
15+
16+
To open Cypress and execute tests interactively, run:
17+
18+
```react
19+
pnpm -F=react run cypress:open
20+
```
21+
22+
To run Cypress on the command line, run:
23+
24+
```react
25+
pnpm -F=react run cypress:run
26+
```
27+
28+
## Regenerating GraphQL queries
29+
30+
Most of the GraphQL queries this library makes are assembled dynamically at runtime based on the user's application and the metadata that comes from their API client. For queries we issue against our static part of the GraphQL schema that each application shares though (under `gadgetMeta { ... }`), we have an automatic type-safe GraphQL query generator in place using `graphql-codegen`.
31+
32+
You can author queries using the `graphql` helper, and then generate types for their return values with
33+
34+
```
35+
pnpm -F=react gql-gen
36+
```
37+
38+
Note that it uses the real Gadget app's GraphQL schema to generate types. The URL for the schema is defined in the `packages/react/codegen.ts` file. You may need to add `NODE_TLS_REJECT_UNAUTHORIZED=0` environment variable before running the command if you're having issues with the SSL certificate and you're using a self-signed certificate.
39+
40+
See the [`graphql-codegen`](https://the-guild.dev/graphql/codegen/docs/guides/react-vue#writing-graphql-queries) docs for more info.
41+
42+
## Prereleasing
1143

1244
It can be annoying to work with these packages via `pnpm link` sometimes, so we also support building and releasing the package to a git SHA which can then be installed conventionally in another repo. To push a prerelease, run `pnpm --filter=@gadgetinc/api-client-core prerelease`. This will:
1345

@@ -16,7 +48,7 @@ It can be annoying to work with these packages via `pnpm link` sometimes, so we
1648
- push that to the remote git repo
1749
- and log out a version you can then refer to from other repos
1850

19-
# Checking test bundle sizes
51+
## Checking test bundle sizes
2052

2153
We have a small project setup for evaluating what the bundled size of these dependencies might be together. Run:
2254

@@ -28,7 +60,7 @@ to build the test bundles.
2860

2961
You can then view the built test bundle size reports at `packages/test-bundles/dist/<bundle>-stats.html` or import the `<bundle>-webpack-stats.json` file into your favourite bundle size analysis tool.
3062

31-
# Releasing
63+
## Releasing
3264

3365
Releasing is done automatically via [our release workflow](.github/workflows/release.yml). Any commits to the main branch that changes one of our `packages/**/package.json` versions will automatically be published.
3466

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"@gadget-client/app-with-no-user-model": "^1.10.0",
2727
"@gadget-client/bulk-actions-test": "^1.113.0",
2828
"@gadget-client/full-auth": "^1.9.0",
29+
"@gadget-client/js-clients-test": "1.498.0-development.854",
2930
"@gadget-client/kitchen-sink": "1.5.0-development.200",
3031
"@gadget-client/related-products-example": "^1.865.0",
3132
"@gadget-client/zxcv-deeply-nested": "^1.212.0",

packages/api-client-core/src/GadgetConnection.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export interface GadgetConnectionOptions {
5050
authenticationMode?: AuthenticationModeOptions;
5151
websocketsEndpoint?: string;
5252
subscriptionClientOptions?: GadgetSubscriptionClientOptions;
53-
websocketImplementation?: typeof WebSocket;
53+
websocketImplementation?: typeof globalThis.WebSocket;
5454
fetchImplementation?: typeof globalThis.fetch;
5555
environment?: string;
5656
requestPolicy?: ClientOptions["requestPolicy"];
@@ -84,10 +84,10 @@ export class GadgetConnection {
8484
static version = "<prerelease>" as const;
8585

8686
// Options used when generating new GraphQL clients for the base connection and for for transactions
87-
private endpoint: string;
87+
readonly endpoint: string;
8888
private subscriptionClientOptions?: SubscriptionClientOptions;
8989
private websocketsEndpoint: string;
90-
private websocketImplementation?: typeof WebSocket;
90+
private websocketImplementation?: typeof globalThis.WebSocket;
9191
private _fetchImplementation: typeof globalThis.fetch;
9292
private environment: string;
9393
private exchanges: Required<Exchanges>;

packages/react/.storybook/main.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/** @type { import('@storybook/react-vite').StorybookConfig } */
2+
const config = {
3+
stories: ["../spec/**/*.stories.@(js|jsx|mjs|ts|tsx)"],
4+
addons: [
5+
"@storybook/addon-onboarding",
6+
"@storybook/addon-links",
7+
"@storybook/addon-essentials",
8+
"@chromatic-com/storybook",
9+
"@storybook/addon-interactions",
10+
],
11+
framework: {
12+
name: "@storybook/react-vite",
13+
options: {},
14+
},
15+
};
16+
export default config;
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/** @type { import('@storybook/react').Preview } */
2+
import "@shopify/polaris/build/esm/styles.css";
3+
4+
const preview = {
5+
parameters: {
6+
controls: {
7+
matchers: {
8+
color: /(background|color)$/i,
9+
date: /Date$/i,
10+
},
11+
},
12+
},
13+
};
14+
15+
export default preview;

packages/react/codegen.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import type { CodegenConfig } from "@graphql-codegen/cli";
2+
3+
const config: CodegenConfig = {
4+
schema: "https://js-clients-test--development.gadget.app/api/graphql",
5+
documents: ["src/**/*.tsx"],
6+
ignoreNoDocuments: true, // for better experience with the watcher
7+
emitLegacyCommonJSImports: false,
8+
generates: {
9+
"./src/internal/gql/": {
10+
preset: "client",
11+
presetConfig: {
12+
fragmentMasking: false,
13+
},
14+
config: {
15+
useTypeImports: true,
16+
},
17+
},
18+
},
19+
};
20+
21+
export default config;

packages/react/cypress.config.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { defineConfig } from "cypress";
2+
3+
export default defineConfig({
4+
component: {
5+
devServer: {
6+
framework: "react",
7+
bundler: "vite",
8+
viteConfig: {
9+
define: {
10+
process: { env: { ...process.env } },
11+
},
12+
},
13+
},
14+
setupNodeEvents(on, config) {
15+
on("before:browser:launch", (_browser, launchOptions) => {
16+
if (process.env["CI"]) {
17+
// try to fix https://github.com/cypress-io/cypress/issues/29860
18+
launchOptions.args.push("--disable-gpu");
19+
}
20+
return launchOptions;
21+
});
22+
},
23+
},
24+
retries: process.env["CI"] ? 2 : 0,
25+
});

0 commit comments

Comments
 (0)