weixin_39804631
2021-01-12 14:37 阅读 0

Auto-injected __typename is being passed to the SQL backend

Hi

I have just implemented Apollo Client 2.0 with VueApollo. I'm having some problems though, and I was hoping you might have some insights or pointers where to look.

A simple apollo: query


rows: gql`query {
  iwRegions {
    id
    country_id
    name
  }
}

is sending an auto-injected '__typename' column request through to my SQL backend server, which naturally has no idea what to do with it.

I tried implementing a suggestion to filter out the _typename as follows, but it has no effect on the problem:


graphQLServer.use('/graphql', graphqlExpress({
  schema: graphQlSchema,
  formatParams: (params) => {
    const { variables, ...rest } = params;
    return {
      variables: omitDeep(variables, '__typename'),
      ...rest
    }
  }
}));

Can you offer any ideas on this?

TIA Adrian

该提问来源于开源项目:vuejs/vue-apollo

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

4条回答 默认 最新

  • weixin_39695306 weixin_39695306 2021-01-12 14:37

    Maybe try filtering it out when creating the SQL query?

    点赞 评论 复制链接分享
  • weixin_39804631 weixin_39804631 2021-01-12 14:37

    Thanks for the quick response!!! I did try that, using:

    
    graphQLServer.use('/graphql', graphqlExpress({
      schema: graphQlSchema,
      formatParams: (params) => {
        const { query, ...rest } = params;
        const newQuery = query.split('__typename\n').join('')
        console.warn('Query: ' + JSON.stringify(newQuery, null, 2))
        return {
          query: newQuery,
          ...rest
        }
      }
    }));
    

    but then it just comes back with a lot of errors complaining about missing __typenames...

    点赞 评论 复制链接分享
  • weixin_39695306 weixin_39695306 2021-01-12 14:37

    I mean in the resolvers, where you effectively make the SQL query. Try to keep __typename as much as possible in the GraphQL part.

    点赞 评论 复制链接分享
  • weixin_39804631 weixin_39804631 2021-01-12 14:37

    The problem was in my objection-graphql middleware, it just needed to filter out the __typename 'column'. Solved!

    点赞 评论 复制链接分享

相关推荐