Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot define multiple queries (with fragments) in a single .graphql file #307

Closed
fpabl0 opened this issue May 10, 2021 · 18 comments
Closed
Labels
bug Something isn't working

Comments

@fpabl0
Copy link

fpabl0 commented May 10, 2021

Before reporting a bug, please test the beta branch!
(Unfortunately I can't test it with the beta branch because it caused a lot of conflicting dependencies problems in my application).

Bug description

When multiple queries are defining in the same file using fragments, Artemis generate a Query with the Fragment declared twice. That causes this exception at runtime:

Captura de Pantalla 2021-05-10 a la(s) 04 38 24

Here it is defined twice:

class GetAllPokemonsQuery
    extends GraphQLQuery<GetAllPokemons$Query, GetAllPokemonsArguments> {
  GetAllPokemonsQuery({this.variables});

  @override
  final DocumentNode document = DocumentNode(definitions: [
    ...
    FragmentDefinitionNode(
        name: NameNode(value: 'pokemonFragment'),
        ...
    ])),
    FragmentDefinitionNode(
        name: NameNode(value: 'pokemonFragment'),
        ...
    ])),
    ...
  ]);
  ...
}

Specs

Artemis version: 6.18.4

build.yaml:
targets:
  $default:
    sources:
      - lib/**
      - graphql/**
      - schema.graphql
      - $package$
    builders:
      artemis:
        options:
          fragments_glob: graphql/fragments/fragments.graphql
          schema_mapping:
            - schema: schema.graphql
              naming_scheme: pathedWithFields
              queries_glob: graphql/*.{query,mutation}.graphql
              output: lib/models/graphql/graphql_api.dart
Artemis output:

The error occurs at runtime.

GraphQL schema:
type Pokemon {
  number: String
  name: String
}

type Query {
  pokemons(first: Int!): [Pokemon]
  pokemon(name: String!): Pokemon!
}
GraphQL query:
# graphql/fragments/fragments.graphql
fragment pokemonFragment on Pokemon {
  number
  name
}

# graphql/pokemon.query.graphql
query getPokemon($name: String!) {
  pokemon(name: $name) {
    ...pokemonFragment
  }
}

query getAllPokemons($first: Int!) {
  pokemons(first: $first) {
    ...pokemonFragment
  }
}
@fpabl0 fpabl0 added the bug Something isn't working label May 10, 2021
@ramyak-mehra
Copy link

having the same issue

@vasilich6107
Copy link
Collaborator

vasilich6107 commented May 11, 2021

I tried to reporduce your issue but I do not have any issues. Here is generated code

@override
  final DocumentNode document = DocumentNode(definitions: [
    FragmentDefinitionNode(
        name: NameNode(value: 'pokemonFragment'),
        typeCondition: TypeConditionNode(
            on: NamedTypeNode(
                name: NameNode(value: 'Pokemon'), isNonNull: false)),
        directives: [],
        selectionSet: SelectionSetNode(selections: [
          FieldNode(
              name: NameNode(value: 'number'),
              alias: null,
              arguments: [],
              directives: [],
              selectionSet: null),
          FieldNode(
              name: NameNode(value: 'name'),
              alias: null,
              arguments: [],
              directives: [],
              selectionSet: null)
        ])),
    OperationDefinitionNode(
        type: OperationType.query,
        name: NameNode(value: 'getPokemon'),
        variableDefinitions: [
          VariableDefinitionNode(
              variable: VariableNode(name: NameNode(value: 'name')),
              type: NamedTypeNode(
                  name: NameNode(value: 'String'), isNonNull: true),
              defaultValue: DefaultValueNode(value: null),
              directives: [])
        ],
        directives: [],
        selectionSet: SelectionSetNode(selections: [
          FieldNode(
              name: NameNode(value: 'pokemon'),
              alias: null,
              arguments: [
                ArgumentNode(
                    name: NameNode(value: 'name'),
                    value: VariableNode(name: NameNode(value: 'name')))
              ],
              directives: [],
              selectionSet: SelectionSetNode(selections: [
                FragmentSpreadNode(
                    name: NameNode(value: 'pokemonFragment'), directives: [])
              ]))
        ]))
  ]);

@vasilich6107
Copy link
Collaborator

@fpabl0 as you see - there is only one FragmentDefinitionNode.
Check your pubspec.yaml for correct version of atremis

@fpabl0
Copy link
Author

fpabl0 commented May 11, 2021

as you see - there is only one FragmentDefinitionNode.

The first query is generated fine, the problem is the second one GetAllPokemonsQuery.

Check your pubspec.yaml for correct version of atremis

I am sure it is 6.18.4:
Captura de Pantalla 2021-05-11 a la(s) 12 19 05

pubspec.lock:
Captura de Pantalla 2021-05-11 a la(s) 12 20 16

@fpabl0
Copy link
Author

fpabl0 commented May 11, 2021

Maybe this issue is already solved in beta branch? As I said above, I can't test it in the beta branch because it causes me conflicting dependencies problems, but I can try a clean project to test this issue if that is the case.

@vasilich6107
Copy link
Collaborator

The beta branch is null safety only.

@fpabl0
Copy link
Author

fpabl0 commented May 11, 2021

The beta branch is null safety only.

I see, your tests were done in the beta branch right?

@vasilich6107
Copy link
Collaborator

haha.
I missed that your fragments was in separate file
now I reproduced the issue

@vasilich6107
Copy link
Collaborator

Fixed in 7.0.0-beta.11
Are you ok to migrate to nullsafety?

@fpabl0
Copy link
Author

fpabl0 commented May 11, 2021

Fixed in 7.0.0-beta.11

Great! Thanks :)

Are you ok to migrate to nullsafety?

Unfortunately no 😞, some of my dependencies are not nullsafety yet.

@ramyak-mehra
Copy link

Fixed in 7.0.0-beta.11
Are you ok to migrate to nullsafety?

Is there a way in which we can generate all the fragments in one file and rest of the stuff in different files?

@vasilich6107
Copy link
Collaborator

@ramyak-mehra not for now

@vasilich6107
Copy link
Collaborator

@fpabl0 what are they?
It’s strange to hear that there is still non migrated packages or substitution exists)

@vasilich6107
Copy link
Collaborator

@ramyak-mehra to give you more context I would add that there are some requests from time to time about separation of output but they are quite different. So the next day we implement some of them there will be a new request...
For now the most reasonable approach is to generate output files - one per schema.

@ramyak-mehra
Copy link

@ramyak-mehra to give you more context I would add that there are some requests from time to time about separation of output but they are quite different. So the next day we implement some of them there will be a new request...
For now the most reasonable approach is to generate output files - one per schema.

Yeah I mean it makes sense for the most part, it was just another way I was looking at things.

@fpabl0
Copy link
Author

fpabl0 commented May 11, 2021

@fpabl0 what are they?
It’s strange to hear that there is still non migrated packages or substitution exists)

Basically my app needs bluetooth, so I am using this one: https://github.com/Polidea/FlutterBleLib. The problem is that Polidea was acquired by other company and they are trying to get new maintainers currently. It has a null-safety branch but I am worried if that is stable as the non-null-safety one is. There are other libraries for bluetooth, but I had many runtime errors with them, so I kept Polidea library.

Anyway, I will give it a chance. Thank you very much for your help. This is an amazing library :)

@vasilich6107
Copy link
Collaborator

It’s a good time to try. In one day there will be no option besides the null safety :-)

@fpabl0
Copy link
Author

fpabl0 commented May 11, 2021

It’s a good time to try. In one day there will be no option besides the null safety :-)

Yes, you are right. I'll try 😄. You can close already this issue if that is ok for you :) as it is already solved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants