Skip to content

Some Basic Questions #5

@TheServerAsterisk

Description

@TheServerAsterisk

I have few questions many of them are more so due to the fact I having some difficulty flowing the flow of the crate.

  1. How do arguments work and how do I parse them?

For example, the graphql docs gives the example

query DroidById($id: ID!) {
  droid(id: $id) {
    name
  }
}
{
   id: [1,2] // lets pretend r2d2 and 3cpo are id 1 and 2 
}

I can see that there is an argument struct so would I pass them in like so?

graphql_object!(<'a> &'a Droid: Database as "Droid" |&self| {
    description: "A mechanical creature in the Star Wars universe."

    interfaces: [&Character]

    field id(id: juniper::Arguments) -> &str as "The id of the droid" {
        self.id()
    }
...

Given a list of the above do I have expose two different Query Roots? One for Droids and the other Driod? That is, if we changed the Query root to

graphql_object!(Database: Database as "Query" |&self| {
    ...
    field droid(
        id: String as "id of the droid"
    ) -> Option<&Vec<Droid>> {
        self.get_droid(&id)
    }
 ...

Which I guess would work if the get_droid method returned Option<&Vec> and rustc would serialize it.

My apologies for these basic questions, but it just not clicking for me. 😞

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions