0

我正在为我的本地环境设置一个模拟服务器。我可以用数据为服务器播种,但是当我查询我的模拟服务器时,Graphql 请求陷入了加载状态。

我首先使用 mirage 创建模拟服务器 server.js

export function makeServer() {
  createServer({
    routes() {
      this.post('/graphql', createGraphQLHandler(graphQLSchema, this.schema));
    },

    seeds(server) {
      server.create('Movie', {
        title: 'The Lord of the Rings: The Fellowship of the Ring',
      });
      server.create('Movie', {
        title: 'The Lord of the Rings: The Two Towers',
      });
      server.create('Movie', {
        title: 'The Lord of the Rings: The Return of the King',
      });
    },
  });
}

我在我的 App.js 文件中启动这个服务器

if (process.env.NODE_ENV === 'development') {
  makeServer({ environment: 'development' });
}

export const client = new ApolloClient({
  uri: process.env.PEOPLE_API,
  cache: new InMemoryCache(),
});

最后我尝试在我的组件中查询服务器。

const movieQuery = gql`
  query Movie {
    movie {
      id
      title
    }
  }
`;

 const { loading, data, error } = useQuery(movieQuery);

当我调出加载状态时,它总是正确的,我永远不会收到数据。

4

0 回答 0