Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding sandbox with creds includes, but from my own account #2419

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions docs/rtk-query/usage/examples.mdx
Original file line number Diff line number Diff line change
@@ -76,6 +76,22 @@ The example has some intentionally wonky behavior... when editing the name of a
sandbox="allow-modals allow-forms allow-popups allow-scripts allow-same-origin"
></iframe>

## React GraphQL with custom client

<iframe
src="https://codesandbox.io/embed/github/reduxjs/redux-toolkit/tree/master/examples/query/reactgraphql-custom-client?fontsize=12&hidenavigation=1&theme=dark&module=%2Fsrc%2Fapi.js&runonclick="
style={{
width: '100%',
height: '800px',
border: 0,
borderRadius: '4px',
overflow: 'hidden',
}}
title="RTK Query GraphQL Example with custom client"
allow="geolocation; microphone; camera; midi; vr; accelerometer; gyroscope; payment; ambient-light-sensor; encrypted-media; usb"
sandbox="allow-modals allow-forms allow-popups allow-scripts allow-same-origin"
></iframe>

## Authentication

There are several ways to handle authentication with RTK Query. This is a very basic example of taking a JWT from a login mutation, then setting that in our store. We then use `prepareHeaders` to inject the authentication headers into every subsequent request.
3 changes: 3 additions & 0 deletions examples/query/react/graphql-custom-client/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SKIP_PREFLIGHT_CHECK=true
# https://github.com/facebook/create-react-app/issues/11940
DISABLE_ESLINT_PLUGIN=true
55 changes: 55 additions & 0 deletions examples/query/react/graphql-custom-client/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{
"name": "@examples-query-react/graphql-custom-client",
"private": true,
"version": "1.0.0",
"description": "",
"keywords": [],
"main": "./src/index.tsx",
"dependencies": {
"@chakra-ui/react": "1.0.0",
"@emotion/react": "^11.4.0",
"@emotion/styled": "^11.3.0",
"@mswjs/data": "^0.3.0",
"@reduxjs/toolkit": "^1.6.0-rc.1",
"@rtk-query/graphql-request-base-query": "^2.0.0",
"faker": "^5.5.3",
"framer-motion": "^2.9.5",
"graphql": "^15.5.0",
"graphql-request": "^3.4.0",
"msw": "0.28.2",
"react": "^18.1.0",
"react-dom": "^18.1.0",
"react-icons": "3.11.0",
"react-redux": "^8.0.2",
"react-router-dom": "6.3.0",
"react-scripts": "5.0.1"
},
"devDependencies": {
"@types/faker": "^5.5.5",
"@types/react": "^18.0.5",
"@types/react-dom": "^18.0.5",
"typescript": "~4.2.4"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"prebuild": "rm -rf dist/"
},
"eslintConfig": {
"extends": [
"react-app"
],
"rules": {
"react/react-in-jsx-scope": "off"
}
},
"browserslist": [
">0.2%",
"not dead",
"not ie <= 11",
"not op_mini all"
],
"msw": {
"workerDirectory": "public"
}
}
44 changes: 44 additions & 0 deletions examples/query/react/graphql-custom-client/public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta
name="description"
content="Web site created using create-react-app"
/>
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
<!--
manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.

Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>React App</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.

You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.

To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
</body>
</html>

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"short_name": "RTK Query Pagination Example",
"name": "Pagination Demo",
"start_url": ".",
"display": "standalone",
"theme_color": "#000000",
"background_color": "#ffffff"
}
Loading
Oops, something went wrong.