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

apollo-parser: ArgumentsDefinition does not seem to be parsed #186

Closed
bnjjj opened this issue Mar 1, 2022 · 2 comments · Fixed by #187
Closed

apollo-parser: ArgumentsDefinition does not seem to be parsed #186

bnjjj opened this issue Mar 1, 2022 · 2 comments · Fixed by #187
Assignees
Labels
apollo-parser bug Something isn't working

Comments

@bnjjj
Copy link
Contributor

bnjjj commented Mar 1, 2022

Need to double check but I create an issue to not forget.
When I try to parse this document:

schema
  @core(feature: "https://specs.apollo.dev/core/v0.2"),
  @core(feature: "https://specs.apollo.dev/join/v0.1", for: EXECUTION)
{
  query: Query
}

directive @core(feature: String!, as: String, for: core__Purpose) repeatable on SCHEMA

directive @join__field(graph: join__Graph, requires: join__FieldSet, provides: join__FieldSet) on FIELD_DEFINITION

directive @join__type(graph: join__Graph!, key: join__FieldSet) repeatable on OBJECT | INTERFACE

directive @join__owner(graph: join__Graph!) on OBJECT | INTERFACE

directive @join__graph(name: String!, url: String!) on ENUM_VALUE

enum core__Purpose {
  EXECUTION
  SECURITY
}

enum CURRENCY_CODE {
  USD
}

type Department {
  category: ProductCategory
  url: String
}

scalar join__FieldSet

enum join__Graph {
  #PRODUCTS @join__graph(name: "products" url: "https://rover.apollo.dev/quickstart/products/graphql")
  PRODUCTS @join__graph(name: "products" url: "http://localhost:4003")
  REVIEWS @join__graph(name: "reviews" url: "https://rover.apollo.dev/quickstart/reviews/graphql")
}

type Money {
  amount: Float
  currencyCode: CURRENCY_CODE
}

"""Here are some helpful details about your type"""
type Price {
  cost: Money

  """A number between 0 and 1 signifying the % discount"""
  deal: Float
  dealSavings: Money
}

"""
This is an Entity, docs:https://www.apollographql.com/docs/federation/entities/
You will need to define a __resolveReference resolver for the type you define, docs: https://www.apollographql.com/docs/federation/entities/#resolving
"""
type Product
  @join__owner(graph: PRODUCTS)
  @join__type(graph: PRODUCTS, key: "id")
  @join__type(graph: REVIEWS, key: "id")
{
  category: ProductCategory @join__field(graph: PRODUCTS)
  description: String @join__field(graph: PRODUCTS)
  id: ID! @join__field(graph: PRODUCTS)
  images(size: Int = 1000): [String] @join__field(graph: PRODUCTS)
  price: Price @join__field(graph: PRODUCTS)
  primaryImage(size: Int = 1000): String @join__field(graph: PRODUCTS)
  reviewSummary: ReviewSummary @join__field(graph: REVIEWS)
  reviews: [Review] @join__field(graph: REVIEWS)
  salesRank(category: ProductCategory = ALL): Int @join__field(graph: PRODUCTS)
  salesRankInCategory: Int @join__field(graph: PRODUCTS)
  salesRankOverall: Int @join__field(graph: PRODUCTS)
  title: String @join__field(graph: PRODUCTS)
  url: String @join__field(graph: PRODUCTS)
}

enum ProductCategory {
  ALL
  BOOKS
  CAMERA_N_PHOTO
  CLOTHING
  ELECTRONICS
  GIFT_CARDS
  VIDEO_GAMES
}

type Query {
  bestSellers(category: ProductCategory = ALL): [Product] @join__field(graph: PRODUCTS)
  categories: [Department] @join__field(graph: PRODUCTS)
  product(id: ID!): Product @join__field(graph: PRODUCTS)
}

"""
This is an Entity, docs:https://www.apollographql.com/docs/federation/entities/
You will need to define a __resolveReference resolver for the type you define, docs: https://www.apollographql.com/docs/federation/entities/#resolving
"""
type Review
  @join__owner(graph: REVIEWS)
  @join__type(graph: REVIEWS, key: "id")
{
  content: String @join__field(graph: REVIEWS)
  id: ID! @join__field(graph: REVIEWS)
  rating: Float @join__field(graph: REVIEWS)
}

type ReviewSummary {
  averageRating: Float
  totalReviews: Int
}

I don't have arguments on bestSellers(category: ProductCategory = ALL): [Product] @join__field(graph: PRODUCTS)

@bnjjj bnjjj added bug Something isn't working apollo-parser labels Mar 1, 2022
@bnjjj bnjjj self-assigned this Mar 1, 2022
@lrlna
Copy link
Member

lrlna commented Mar 1, 2022

oops it definitely isn't! that's because despite the function name and description we are still starting an ARGUMENTS node instead of an ARGUMENTS_DEFINITION node

/// *ArgumentsDefinition*:
/// **(** InputValueDefinition* **)**
pub(crate) fn arguments_definition(p: &mut Parser) {
let _g = p.start_node(SyntaxKind::ARGUMENTS);

quick test case:

    #[test]
    fn it_can_access_arguments_in_fields() {
        let schema = r#"
type Query {
  bestSellers(category: ProductCategory = ALL): [Product] @join__field(graph: PRODUCTS)
  categories: [Department] @join__field(graph: PRODUCTS)
  product(id: ID!): Product @join__field(graph: PRODUCTS)
}
        "#;
        let parser = Parser::new(schema);
        let ast = parser.parse();

        assert!(ast.errors.is_empty());

        let document = ast.document();
        for definition in document.definitions() {
            if let ast::Definition::ObjectTypeDefinition(obj_def) = definition {
                for field in obj_def.fields_definition().unwrap().field_definitions() {
                    if field.name().unwrap().to_string() == "bestSellers" {
                        let argument = field
                            .arguments_definition()
                            .unwrap()
                            .input_value_definitions()
                            .into_iter()
                            .next()
                            .unwrap();
                        assert_eq!(argument.name().unwrap().to_string(), "category");
                        assert_eq!(argument.ty().unwrap().to_string(), "ProductCategory");
                        assert_eq!(argument.default_value().unwrap().to_string(), "ALL");
                    }
                }
            }
        }
    }

@bnjjj
Copy link
Contributor Author

bnjjj commented Mar 1, 2022

Thanks ! Will take a look tomorrow because I need this to generate mutations with apollo-smith

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

Successfully merging a pull request may close this issue.

2 participants