Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

__typename being sent to SQL backend as part of a query? #24

Closed
Trellian opened this issue Nov 15, 2017 · 7 comments
Closed

__typename being sent to SQL backend as part of a query? #24

Trellian opened this issue Nov 15, 2017 · 7 comments

Comments

@Trellian
Copy link

Hi @koskimas,

I'm experiencing a problem with __typename appearing in the final query string being sent to the SQL engine, I'm hoping you can help here. Have you seen anything like this before, or could you point me in a direction that might help?

I'm using Apollo Server Express 1.2.0 and Apollo Client 2.0.2.

I have a simple query that works fine in GraphiQL, but not when sent via the client.

{ 
  iwRegions {
    country_id
    name
  }
}

and I'm getting an error back as follows:

message: "select `iw_region`.`country_id`, `iw_region`.`name`, `__typename` from `iw_region` - ER_BAD_FIELD_ERROR: Unknown column '__typename' in 'field list'"

I've tried raising issues on the GitHub for apollo-client, apollo-server and vue-apollo, but I've not had any response there :(

Any help you can give would be greatly appreciated!

Thank you
Adrian

@koskimas
Copy link
Collaborator

Hi

Here's the code that generates the select clause. Try debugging that. I have no idea why __typename appears in the AST node.

@Trellian
Copy link
Author

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...

@Trellian
Copy link
Author

whoops sorry I replied on the wrong forum!

@koskimas
Copy link
Collaborator

http://graphql.org/learn/queries/#meta-fields

It seems that objection-graphql needs to exclude that property.

@Trellian
Copy link
Author

That did it!

I modified in _filterForSelects() (line 381:

      builder.select(selects.map(it => {
      const col = modelClass.propertyNameToColumnName(it);

        if (jsonSchema.properties[it]) {
          return `${builder.tableRefFor(modelClass)}.${col}`;
        } else {
          return col;
        }
      }));

to

      builder.select(selects.filter(it => {
          return (it !== '__typename');
      }).map(it => {
      const col = modelClass.propertyNameToColumnName(it);

        if (jsonSchema.properties[it]) {
          return `${builder.tableRefFor(modelClass)}.${col}`;
        } else {
          return col;
        }
      }));

Thank you! I just needed a prompt in the right direction.

@koskimas
Copy link
Collaborator

This is now fixed in master. I'll release a new patch version soon.

@Trellian
Copy link
Author

Ha! you beat me to the PR, and I only took 3 minutes! I've never had an author patch an issue that fast on GitHub before, Kudos to you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants