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

Incorrect documentation, how to do it correctly? #31

Closed
Tracked by #5357 ...
AlexeyRaga opened this issue May 23, 2023 · 3 comments
Closed
Tracked by #5357 ...

Incorrect documentation, how to do it correctly? #31

AlexeyRaga opened this issue May 23, 2023 · 3 comments
Assignees

Comments

@AlexeyRaga
Copy link

AlexeyRaga commented May 23, 2023

The documentation for combining multiple sources has this code:

  extend type Book {
    author: authors_v1_Author @resolveTo(
      sourceName: "Authors" # Which source does the target field belong to?
      sourceTypeName: "Query", # Which root type does the target field belong to?
      sourceFieldName: "authors_v1_AuthorsService_GetAuthor", # What is the source field name?
      requiredSelectionSet: "{ authorId }",
      sourceArgs: # What args does this need to take? {
        "input.id": "{root.authorId}"
      }
    )
  }

It has missing commas and misplaced comments, but even after fixing those I cannot figure out how to make it work.

I now have it as

additionalTypeDefs: |
  extend type Book {
    author: authors_v1_Author @resolveTo(
      sourceName: "Authors",
      sourceTypeName: "Query",
      sourceFieldName: "authors_v1_AuthorsService_GetAuthor",
      requiredSelectionSet: "{ authorId }",
      sourceArgs: {
        "input.id": "{root.authorId}"
      }
    )
  }

And here is the error message that I get:

Mesh AggregateError: Failed to find any GraphQL type definitions in: extend type Book {
  author: authors_v1_Author @resolveTo(
    sourceName: "Authors",
    sourceTypeName: "Query",
    sourceFieldName: "authors_v1_AuthorsService_GetAuthor",
    requiredSelectionSet: "{ authorId }",
    sourceArgs: {
      "input.id": "{root.authorId}"
    }
  )
}
;
 - ENAMETOOLONG: name too long, stat '/service/extend type Book {
  author: authors_v1_Author @resolveTo(
    sourceName: "Authors",
    sourceTypeName: "Query",
    sourceFieldName: "authors_v1_AuthorsService_GetAuthor",
    requiredSelectionSet: "{ authorId }",
    sourceArgs: {
      "input.id": "{root.authorId}"
    }
  )
}

Using additionalResolvers in yaml works, but I still want to make it work in this more explicit way.

I am using the following versions of packages:

  "dependencies": {
    "@graphql-mesh/cli": "^0.82.35",
    "@graphql-mesh/graphql": "^0.93.1",
    "@graphql-mesh/openapi": "^0.93.1",
    "@graphql-mesh/grpc": "^0.93.2",
    "@graphql-mesh/runtime": "^0.93.2",
    "@graphql-mesh/transform-filter-schema": "^0.93.2",
    "@graphql-mesh/transform-rename": "^0.93.1",
    "graphql": "^16.3.0"
  }

Can anyone please advise on how to make it work?

@AlexeyRaga
Copy link
Author

I figured that the problem is most likely in this block:

      sourceArgs: {
        "input.id": "{root.authorId}"
      }

I tried to write it differently, for example

      sourceArgs: {
        input: { id: "{root.authorId}" }
      }

This one starts properly, but then I get the following error when querying:

"message": "additionalResolver.sourceArgs[argPath].toString is not a function"

and some other variations but it didn't help.

@sraza-onshape
Copy link

sraza-onshape commented Jul 4, 2023

Hi @AlexeyRaga, I ran into a similar issue. This is just my best guess, but I believe the root cause is that (at least for the version of the library you/I are using), the @resolve() function is no longer supposed to be used under the additionalTypeDefs property in .meshrc.yaml file.

I believe what you're supposed to do now is use the additionalResolvers property in the file, to separate concerns from the additional type fields. This is what I have in mine, to give you an idea:

# .meshrc.yaml
...
additionalTypeDefs: |
  ...
  extend type Book {
    author: authors_v1_Author
  }
additionalResolvers:
  ... 
  - targetTypeName: Book
    targetFieldName: author
    sourceName: Authors # Which source does the target field belong to?
    sourceTypeName: Query # Which root type does the target field belong to?
    sourceFieldName: authors_v1_AuthorsService_GetAuthor # What is the source field name?
    requiredSelectionSet:
      |
      {
        authorId
      }
    sourceArgs: # What args does this need to take?
      input.id: "{root.authorId}"

The full source code is available here so you can look. I think the main point is just to move the logic from @resolve() under additionalResolvers.

@ardatan
Copy link
Collaborator

ardatan commented Aug 23, 2023

the @resolve() function is no longer supposed to be used under the additionalTypeDefs property in .meshrc.yaml file.

This is not true, actually :)

@resolveTo directive is still the recommended way of extending the schema. The code in this example has recently been updated. Please let us know if the issue still persists.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants