jignesh.world
jignesh.world

Reputation: 1446

How to use GraphQL Fragments in Flutter?

Can anyone please help or direct me towards the reference,

how can we implement GraphQL Fragments in Flutter?

GraphQL Fragments Reference: https://graphql.org/learn/queries/#fragments

Upvotes: 0

Views: 1299

Answers (2)

Alish Giri
Alish Giri

Reputation: 2238

You can implement GraphQL fragments using graphql_flutter package as below.

mutation RegisterUser($input: UserInput!) {
  auth {
    register(input: $input) {
      ...RegisterSuccess
    }
  }
}

fragment RegisterSuccess on RegisterSuccess {
  userId
}

You can also make multiple fragments of the same type based on what you want to extract.

fragment User on User {
  id
  name
  email
  address
  phoneNumber
  emailVerified
  registeredDate
}

fragment BuyerInfo on User {
  id
  name
  email
  phoneNumber
}

For more detail checkout this article Flutter and GraphQL with Authentication.

Upvotes: 0

mskolnick
mskolnick

Reputation: 1172

Artemis (Apollo's Sister ;) ) is the only viable GraphQL code generator that I have found to date. I've only gotten it working correctly with my schema on the latest beta version though.

https://pub.dev/packages/artemis

Upvotes: 1

Related Questions