Query question 0.2.X


#1

Hi guys,

Im migrating a Functional test app made on 0.1.X to 0.2.X.

Now my queries must be independent or maybe i dont know how to concatenate them like. In 0.1.X i could have more than one querie in one connect. In 0.2.X gql prompts:

Uncaught Error: Queries must have exactly one operation definition.

Thats cool… i know its right because each component should have its own query and not one component all the queries and give the props to the children. Isnt it ?


#2

Can you paste the GraphQL snippet here?


#3

Of course, im sorry,

Here is what it looks now:

const GET_SOMETHING = gql`
  query getSeomething{
    something{
      columnA
      columnB
      columnC
    }
  }
`;

so every time i need to refetch now i must call the this.props.data.refetch()

in the past i could have this inside the gql tag:

query getSomething{
    something{
      columnA
    }
}
query getSomethingB{
    somethingB{
      columnA
      columnB
    }
}

#4

You could never have two operation definitions, AFAIK. Try this:

query getSomething{
    something{
      columnA
    }
    somethingB{
      columnA
      columnB
    }
}

#5

Yes, thats works perfectly.

Now i only want to refetch something and not both, this.props.data.refetch() will bring the whole query. In the past i could call this.props.something.refetch(). Is there anyway to achieve this ?


#6

Ah, sounds like you are referring to transitioning from the old connect API from react-apollo to the new graphql one. The old container allowed multiple queries in one container, but now you need to make one container per query you want to refetch. This makes the API a bit simpler since you don’t need to deal with as many nested objects.

You can control the prop the query is passed under using the name option: http://docs.apollostack.com/apollo-client/react.html#graphql-props


#7

Mmm is not what i want, is my problem in fact, i was not thinking in REACT way. I was seeking to implement two queries in one component, but i will stick to the react cycle and create two different components for each problem.

Thanks @sashko