reactive/data-client / .agents/skills/data-client-graphql-setup
data-client-graphql-setup
VerifiedSet up @data-client/graphql for GraphQL APIs. Configures GQLEndpoint with auth and custom options. Use after data-client-setup detects GraphQL patterns.
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 4.9 KB |
| references.json | config | 104 B |
| references/auth.md | markdown | 1.9 KB |
references/auth.md
View on GitHub<!-- Generated by `yarn build:skills` from docs/graphql/auth.md (react). Edit the source doc, not this file. -->
# GraphQL Authentication
## Cookie Auth
Here's an example using simple cookie auth:
```ts title="schema/endpoint.ts"
import { GQLEndpoint } from '@data-client/graphql';
class CookieGQLEndpoint extends GQLEndpoint<any> {
getRequestInit(variables: any): RequestInit {
return {
...super.getRequestInit(variables),
credentials: 'same-origin',
};
}
}
export const gql = new CookieGQLEndpoint(
'https://nosy-baritone.glitch.me',
);
export default gql;
```
## Access Tokens
Here we'll keep the access token in a module variable and send it in a header. Endpoints made with
`gql.query()` and `gql.mutation()` copy `gql` when they are created, so a value set on `gql` afterward
would not reach them; a module variable is read on every request.
```ts title="schema/endpoint.ts"
import { GQLEndpoint } from '@data-client/graphql';
let accessToken = '';
export function setAccessToken(token: string) {
accessToken = token;
}
export const gql = new GQLEndpoint('https://nosy-baritone.glitch.me', {
getHeaders(headers: HeadersInit): HeadersInit {
return {
...headers,
'Access-Token': accessToken,
};
},
});
export default gql;
```
Then be sure to set the access token upon login:
```ts
import { setAccessToken } from 'schema/endpoint';
function Auth() {
const handleLogin = useCallback(
async e => {
const { accessToken } = await login(new FormData(e.target));
// success!
setAccessToken(accessToken);
},
[login],
);
return <AuthForm onSubmit={handleLogin} />;
}
```
## 401 Logout Handling
In case a users authorization expires, the server will typically responsd to indicate
as such. The standard way of doing this is with a 401. [LogoutManager](https://dataclient.io/docs/api/LogoutManager)
can be used to easily trigger any de-authorization cleanup.
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| receiving-code-reviewobra/superpowersUse when receiving code review feedback, before implementing suggestions, especially if feedback seems unclear or technically questionable - requires technical rigor and verification, not performative agreement or blind implementation | Stars: 319k | Updated | Claude CodeCodex | Verified | Install |
| requesting-code-reviewobra/superpowersUse when completing tasks, implementing major features, or before merging to verify work meets requirements | Stars: 319k | Updated | Claude CodeCodex | Verified | Install |
| using-git-worktreesobra/superpowersUse when starting feature work that needs isolation from current workspace or before executing implementation plans - ensures an isolated workspace exists via native tools or git worktree fallback | Stars: 319k | Updated | Claude CodeCodex | Verified | Install |
| verification-before-completionobra/superpowersUse when about to claim work is complete, fixed, or passing, before committing or creating PRs - requires running verification commands and confirming output before making any success claims; evidence before assertions always | Stars: 319k | Updated | Claude CodeCodex | Verified | Install |