- 在应用程序根部使用 Apollo Provider:
- 全局可用性:确保在 React 应用程序的根组件(例如
App.js或index.js)中使用ApolloProvider包裹整个应用,以便所有子组件都能访问 Apollo Client 实例。 - Client 实例配置:在
ApolloProvider中传入已配置好的ApolloClient实例,该实例应包含uri(GraphQL 服务器地址)和cache(缓存策略,通常是InMemoryCache)等必要配置。 - 示例:
// index.js 或 App.js import React from 'react'; import ReactDOM from 'react-dom/client'; import { ApolloClient, InMemoryCache, ApolloProvider, gql } from '@apollo/client'; import App from './App'; const client = new ApolloClient({ uri: 'YOUR_GRAPHQL_ENDPOINT', cache: new InMemoryCache(), }); ReactDOM.createRoot(document.getElementById('root')).render( <React.StrictMode> <ApolloProvider client={client}> <App /> </ApolloProvider> </React.StrictMode>, ); - 中间件与错误处理:在
ApolloClient配置中,可以添加link来处理认证、错误重试、文件上传等高级功能,例如使用HttpLink、AuthLink、ErrorLink等。
- 全局可用性:确保在 React 应用程序的根组件(例如
Apollo GRAPHQL Apollo Provider Setup
要求在应用程序根部使用 Apollo Provider
Apollo GRAPHQL Apollo Provider Setup by liaosw97 · b3f7a96
npx skillmds@latest add liaosw97/apollo-graphql-apollo-provider-setup File contents
---name: apollo-graphql-apollo-provider-setupdescription: 要求在应用程序根部使用 Apollo Provider---- **在应用程序根部使用 Apollo Provider**: - **全局可用性**:确保在 React 应用程序的根组件(例如 `App.js` 或 `index.js`)中使用 `ApolloProvider` 包裹整个应用,以便所有子组件都能访问 Apollo Client 实例。 - **Client 实例配置**:在 `ApolloProvider` 中传入已配置好的 `ApolloClient` 实例,该实例应包含 `uri`(GraphQL 服务器地址)和 `cache`(缓存策略,通常是 `InMemoryCache`)等必要配置。 - **示例**: ```javascript // index.js 或 App.js import React from 'react'; import ReactDOM from 'react-dom/client'; import { ApolloClient, InMemoryCache, ApolloProvider, gql } from '@apollo/client'; import App from './App'; const client = new ApolloClient({ uri: 'YOUR_GRAPHQL_ENDPOINT', cache: new InMemoryCache(), }); ReactDOM.createRoot(document.getElementById('root')).render( <React.StrictMode> <ApolloProvider client={client}> <App /> </ApolloProvider> </React.StrictMode>, ); ``` - **中间件与错误处理**:在 `ApolloClient` 配置中,可以添加 `link` 来处理认证、错误重试、文件上传等高级功能,例如使用 `HttpLink`、`AuthLink`、`ErrorLink` 等。
liaosw97/awesome-rules-skills/tree/main/plugins/apollo-graphql/skills/apollo-graphql-apollo-provider-setup commit b3f7a96605
Frequently asked questions
Run npx skillmds@latest add liaosw97/apollo-graphql-apollo-provider-setup in your terminal (requires Node.js), paste this page's agent-chat prompt into Claude, Cursor, or any MCP-connected agent, or download the SKILL.md file and copy it into your agent's skills directory.
要求在应用程序根部使用 Apollo Provider It is listed under Integrations & APIs on SkillMD.
This skill has not completed SkillMD's automated safety review yet. Capability flags: docs only. SkillMD never runs a skill's scripts for you; review the SKILL.md before installing.
This skill is tagged as working with Claude Code, Claude.ai, OpenAI Codex. SKILL.md is an open format, so most agents that read a skills directory can load it too.
Yes. Installing skills from SkillMD is free, and the skill stays under its author's original license.
liaosw97 (@liaosw97) published this skill. Their other Agent Skills are listed on their SkillMD profile.