简体   繁体   中英

GraphQL queries via Apollo

Hi I'm working on an Android app and I need to use GraphQL. I'm trying to use the Apollo client first by following this tutorial as practice but am having trouble following it through. It just lacks some specific information and details that would be helpful.

Currently what I'm stuck at is trying to construct a .graphql file. I was hoping to at least compile the code and make sure everything up to this point was fine, but apparently you can't even compile it without providing at least one .graphql file.

I've included the example given in the tutorial below, my confusion mainly comes from what exactly is "FeedQuery" and "FeedType"? Are they classes defined for this particular example or are they classes generated by Apollo itself to define any query? So should I just use those two classes when defining my own queries or make equivalents? And are those parameters also something required in the defintion or something specific to the examples strucutre?

I can't seem to find more information about this in their tutorial or website. It's tough enough trying to learn GraphQL but the lack of details in this tutorial is making things a lot more frustrating. If they had shared what the structure looks like in this tutorial it would have been really helpful but it doesn't seem to be included.

query FeedQuery($type: FeedType!, $limit: Int!) {
  feedEntries: feed(type: $type, limit: $limit) {
    id
    repository {
      name
    }
    postedBy {
      login
    }
  }
}

Thank you for your help, and if anyone has a link to a better tutorial I'd really appreciate it.

I the context of the GraphQL DSL, FeedQuery is a named query (think of it as a method in Java terms) that you can use to retrieve specific data (as described by the internals of the query) from a GraphQL server.

To retrieve the desired data, you need to pass in two non-null arguments (denoted by the ! ), the feedType and the limit. The first is a custom type defined by the GraphQL schema implemented by the server. The second is a GraphQL scalar type.

Both the FeedQuery and FeedType will be converted to Java objects during compilation phase. For queries, you will be provided with an appropriate builder to include all the necessary information to perform the actual call.

You can read a complete Java example here . It is a more complete version of the tutorial you are following.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM