Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Graphql Apollo客户端订阅可在游乐场使用,但不能在expo应用程序中使用_Graphql_Expo_Subscription_React Apollo_Apollo Client - Fatal编程技术网

Graphql Apollo客户端订阅可在游乐场使用,但不能在expo应用程序中使用

Graphql Apollo客户端订阅可在游乐场使用,但不能在expo应用程序中使用,graphql,expo,subscription,react-apollo,apollo-client,Graphql,Expo,Subscription,React Apollo,Apollo Client,订阅在操场上工作并返回预期字段,但在apollo graphql客户端中不工作,它不返回任何内容!以下是在游乐场和客户端中使用的查询: export const PARTY_SUBSCRIPTION = gql` subscription onPartyUpdated($hostname: String!) { party(hostname: $hostname) { mutation node { id users {

订阅在操场上工作并返回预期字段,但在apollo graphql客户端中不工作,它不返回任何内容!以下是在游乐场和客户端中使用的查询:

export const PARTY_SUBSCRIPTION = gql`
  subscription onPartyUpdated($hostname: String!) {
    party(hostname: $hostname) {
      mutation
      node {
        id
        users {
          username
        }
        open
        hostname
      }
    }
  }
`;
这是我的apollo客户端配置文件:

const DEV_DB_ENDPOINT = "http://192.168.1.3:4000/";

const authLink = setContext(async (_, { headers }) => {
  const token = await AsyncStorage.getItem("userToken");
  return {
    headers: {
      ...headers,
      authorization: token ? `Bearer ${token}` : ""
    }
  };
});

const wsLink = new WebSocketLink({
  uri: "ws://localhost:5000/",
  options: {
    reconnect: true
  }
});
const httpLink = new HttpLink({
  uri: DEV_DB_ENDPOINT,
  credentials: "same-origin"
});

const link = split(
  // split based on operation type
  ({ query }) => {
    const definition = getMainDefinition(query);
    console.log(query);
    return (
      definition.kind === "OperationDefinition" &&
      definition.operation === "subscription"
    );
  },
  wsLink,
  httpLink
);

const client = new ApolloClient({
  link: ApolloLink.from([
    onError(({ graphQLErrors, networkError }) => {
      if (graphQLErrors)
        graphQLErrors.map(({ message, locations, path }) =>
          console.log(
            `[GraphQL error]: Message: ${message}, Location: ${locations}, Path: ${path}`
          )
        );

      if (networkError) console.log(`[Network error]: ${networkError}`);
    }),
    authLink,
    link
  ]),
  cache: new InMemoryCache()
});

export { client };
这是我的订阅组件

<Subscription
  subscription={PARTY_SUBSCRIPTION}
  variables={{
    hostname: "Amir004"
  }}
  onError={err => console.log(err)}
  onCompleted={data => console.log(data)}
>
  {() => {
    return <Text>Current list of friends in your party : </Text>;
  }}
</Subscription>
console.log(err)}
onCompleted={data=>console.log(数据)}
>
{() => {
返回您的好友的当前列表:;
}}
该组件没有console.log任何错误或数据


非常感谢您的帮助:)

对于仍在努力解决此问题的任何人,使用查询组件和调用subscribeToMore似乎是可行的!我仍然不知道什么是源问题,目前,我只能使用查询组件订阅!
有关subscribeToMore的更多信息:

对于仍在努力解决此问题的任何人,使用查询组件和调用subscribeToMore似乎是可行的!我仍然不知道什么是源问题,目前,我只能使用查询组件订阅!
有关subscribeToMore的更多信息:

本地主机:5000是正确的端点吗?大概它应该指向与您的
HttpLink
相同的服务器,或者至少不应该是
localhost
,因为您正在移动设备上运行。@DanielRearden我尝试将websocket链接设置为“”但是什么都没有改变。你真的通过调用
pubsub.publish
触发订阅服务器端吗?我使用的是prisma,代码在服务器端运行得很好,下面是我的订阅解析程序:
const subscription={party:{subscribe:{subscribe:{parent,{hostname},{prisma},info)=>{console.log(hostname);返回prisma.subscription.party({where:{node:{hostname}},info);}}}
我相信问题出在前端,但我仍然找不到它
localhost:5000
正确的端点?大概它应该指向与您的
HttpLink
相同的服务器,或者至少不应该是
localhost
,因为您正在移动设备上运行。@DanielRearden我尝试将websocket链接设置为“”但是什么都没有改变。你真的通过调用
pubsub.publish
触发订阅服务器端吗?我使用的是prisma,代码在服务器端运行得很好,下面是我的订阅解析程序:
const subscription={party:{subscribe:{subscribe:{parent,{hostname},{prisma},info)=>{console.log(hostname);返回prisma.subscription.party({where:{node:{hostname}},info);}}}我相信问题在前端,但我仍然找不到它