Git Product home page Git Product logo

Comments (6)

knaeckeKami avatar knaeckeKami commented on June 8, 2024 1

The way do to this with ferry is to use a fragment

fragment BasePokemonInfo on Pokemon {
    id
    name
    type
}

and then reuse this fragment

query Pokemon0($id: ID!) {
  pokemon(id: $id) {
    ...BasePokemonInfo
  }
}
# lib/graphql/query.pokemon_1.graphql

query Pokemon1($id: ID!) {
  pokemon(id: $id) {
     ...BasePokemonInfo
     weight
  }
}

This will generate an abstract class GBasePokemonInfo and the types on both queries will implement this fragment.

from ferry.

knaeckeKami avatar knaeckeKami commented on June 8, 2024 1

I think so. If not, please file a bug ;)

from ferry.

knaeckeKami avatar knaeckeKami commented on June 8, 2024 1

Does that fit your usecase?

It's a little different than what you described, but I think it's safer this way.
If we generated the full type and you used that in your code, your code might break if an additional field is added to the schema.

from ferry.

ValentinVignal avatar ValentinVignal commented on June 8, 2024

Thank you for the suggestion!
Would theGBasePokemonInfoFragment still be generated if it is not used in any query?

from ferry.

ValentinVignal avatar ValentinVignal commented on June 8, 2024

I should fit my use case yes, thank you! I still need to try it out

from ferry.

ValentinVignal avatar ValentinVignal commented on June 8, 2024

I created a fragment (unused anywhere, but it could be used):

# lib/graphql/fragment.pokemon.graphql

fragment PokemonFragment on Pokemon {
  id
  name
  type
}

The generator did create a GPokemonFragmentData class that I can use

// lib/main.dart
void main() {
  final pokemon = GPokemonFragmentData(
    (pokemon) => pokemon
      ..id = 'id'
      ..name = 'name'
      ..type = 'type',
  );
}

Thank you @knaeckeKami, it did fit my use case and is probably safer than what I was asking initially!

Closing the issue

from ferry.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.