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

Apollo does not support anonymous operations #184

Closed
agborkowski opened this issue Jul 21, 2017 · 9 comments
Closed

Apollo does not support anonymous operations #184

agborkowski opened this issue Jul 21, 2017 · 9 comments

Comments

@agborkowski
Copy link

agborkowski commented Jul 21, 2017

version: apollo-codegen 0.15.2

i execute query in graphiql
query { getAllCustomers {id} }

i gets data.getAllCustomers[ids...]

{
  "data": {
    "getAllCustomers": [
      {
        "id": "34"

then i want to execute query under apollo-client/angular-apollo

so i continue with codegen

  • apollo-codegen download-schema http://localhost:3000/graphql --output schema.json
  • apollo-codegen generate src/**/*.gql --schema schema.json --target typescript --output src/app/graphql/schema.ts

schema/json/js

i have only one .gql file with the same query like i executed in graphiql:
query { getAllCustomers {id} }

but schema.ts wont genrate with error

.../main/customers/_graphql/getCustomers.gql: Apollo does not support anonymous operations
error: Validation of GraphQL query document failed

Update

if found problem query withink works in graphql-tag and gprahiql wont generate type script to solve above problem is add

query SOMESTRING { getAllCustomers {id name symbol} }

then apolo codegen will generate

export type SOMESTINGQuery = {
  getAllCustomers:  Array< {
@rricard
Copy link
Contributor

rricard commented Jul 25, 2017

Yes, we need to name the types we generate so we can't really support anonymous queries.

@johndpope
Copy link

johndpope commented Sep 29, 2017

so the example
query SOMESTRING { getAllCustomers {id name symbol} }
is brilliant.

in the code -
you need to throw a warning and say to users
query INSERTQUERYNAMEHERE { getAllCustomers {id name symbol} }
maybe even link back here
#184

or perhaps you could randomize some name? like heroku?

i think that in my usecase - simply grabbing the first parameter and throwing it as the name / would suffice. Then instead of an error - just throw a warning.

public final class SomestringQuery: GraphQLQuery {
  public static let operationString =
    "query SOMESTRING {" +

@langpavel
Copy link

You really MUST report file name where the error happened.
I have app with 50 queries and I really don't want check every file manually

@mcmar
Copy link

mcmar commented May 1, 2019

@rricard Do you think we can re-open this issue in light of @langpavel's comment that we need to report the file name where the error occurred. Checking every query manually is an unreasonable solution to this

@giovannibenussi
Copy link

I was able to debug this by adding temporary logs to the file where the issue was being raised (not the ideal, but it worked for me):

// /usr/local/lib/node_modules/apollo/node_modules/apollo-language-server/lib/project/client.js
if (!definition.name) {
  console.log('definition', definition)
  console.log('document', document)
}

Document will give you information about the file being evaluated so you will be able to solve the issue!

@Enalmada
Copy link

Enalmada commented May 17, 2020

In my case the error was coming from an old commented out query and I had to remove the comment to get it to work. I was only able to discover this after adding console logging like @giovannibenussi suggested. Would have been a bit easier if there was more information in the output.

/*
const ROUND_LIST = gql`
  {
    rounds {
      ...FullRound
    }
  }
  ${fullRoundFragment}
`;
*/

@daniel-washburn-q-free
Copy link

Any update on adding tracing so that we can tell which line number, or at least file, is causing the error?

@ardok
Copy link

ardok commented Nov 11, 2020

Can we add this tracing? As simple as @giovannibenussi console logging would help a tremendous amount.
I finally figured out my error after printing out the document.

@camsjams
Copy link

camsjams commented Mar 3, 2021

The other side of the coin here is what if we just want to skip anonymous operations?

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

Successfully merging a pull request may close this issue.

10 participants