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

BUG: onRequest returns No such file or directory #2796

Closed
2 tasks done
asimpleidea opened this issue Sep 9, 2024 · 11 comments · Fixed by #2797
Closed
2 tasks done

BUG: onRequest returns No such file or directory #2796

asimpleidea opened this issue Sep 9, 2024 · 11 comments · Fixed by #2797
Assignees
Labels
💎 Bounty type: bug Something isn't working.

Comments

@asimpleidea
Copy link
Contributor

asimpleidea commented Sep 9, 2024

Prerequisites

  • I have checked the existing issues to ensure this is not a duplicate.
  • I am running the latest version of Tailcall.

Describe the bug

Custom javascript functions/files seem not to be loaded correctly.

Steps to reproduce

Note

This also happens if you just clone the repo, and run: tailcall start jsonplaceholder_script.graphql.

  1. Create this main.graphql:
schema
  # Specify server configuration: Start GraphQL server at 0.0.0.0:8000
  @server(port: 8000)
  # Specify a base url for all http requests
  @link(type: Script, src: "worker.js")
  @upstream(baseURL: "http://jsonplaceholder.typicode.com", onRequest: "foo") {
  query: Query
}

type Query {
  # Specify the http path for the users query
  users: [User] @http(path: "/users")
}

# Create a user type with the fields returned by the users api

type User {
  id: Int!
  name: String!
  username: String!
  email: String!

  # Extend the user type with the posts field
  # Use the current user's id to construct the path
  posts: [Post] @http(path: "/users/{{.value.id}}/posts")
}

# Create a post type with the fields returned by the posts api
type Post {
  id: Int!
  title: String!
  body: String!
}
  1. Create this worker.js file in the same directory as main.graphql above:
function foo({request}) {
    console.log(`${request.method} ${request.uri.path}`)

    return {request}
}
  1. From the same directory as main.graphql and worker.js run:
tailcall start main.graphql

you will see that the js file was successfully loaded:

 INFO File read: main.graphql ... ok
 INFO File read: worker.js ... ok
 INFO N + 1 detected: 1
 INFO 🚀 Tailcall launched at [127.0.0.1:8000] over HTTP/1.1
 INFO 🌍 Playground: https://tailcall.run/playground/?u=http://127.0.0.1:8000/graphql&utm_source=tailcall-release&utm_medium=server
  1. Go to https://tailcall.run/playground/?u=http://127.0.0.1:8000/graphql&utm_source=tailcall-release&utm_medium=server
  2. Launch this query:
query {
  users {
    id
    name
    posts {
      title
    }
  }
}

the returned response will show that worker.js was not actually loaded:

{
  "data": null,
  "errors": [
    {
      "message": "Worker Error: Error: IO Error: No such file or directory (os error 2)",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ]
    }
  ]
}
  1. From the console you can see:
ERROR error=Worker Error: Error: IO Error: No such file or directory (os error 2)

Expected behavior

The response should not contain an error.

The console should print GET something....

Actual behavior

An error is shown that worker.js was not actually loaded.

Screenshots

Environment information:

  • Operating System: macOS 14.6.1 (M1 Pro)
  • Tailcall Version: tailcall v0.111.2
  • Rust Version: rustc 1.81.0 (eeb90cda1 2024-09-04)
  • GraphQL Client/version curl 8.7.1 (x86_64-apple-darwin23.0)

Additional context

Examples are exactly the same provided from documentation.

Logs

Provided in Steps to reproduce

@asimpleidea asimpleidea changed the title onRequest returns No such file or directory BUG: onRequest returns No such file or directory Sep 9, 2024
@ssddOnTop
Copy link
Member

ssddOnTop commented Sep 9, 2024

I am unable to reproduce the error

I copy pasted the graphql config and worker.js and kept it in the same directory. And it works just fine.

Can you provide some more context?

edit: I think it might be a simple error in the location of files..

@asimpleidea
Copy link
Contributor Author

Thank you for your reply!

I just tried cloning the repo and then running tailcall start jsonplaceholder_script.graphql.

and then just running the user query. Same thing happens to me.

@ssddOnTop
Copy link
Member

got it.. I think you are running it in different dir like

../target/debug/tailcall ... so the root dir is something else and there's an error in resolving path

@ssddOnTop ssddOnTop self-assigned this Sep 9, 2024
@ssddOnTop
Copy link
Member

ssddOnTop commented Sep 9, 2024

I think you are running it in different dir like

@asimpleidea my assumption seems to be incorrect.. it's still working in the case where binary is located in some other dir

@tusharmath
Copy link
Contributor

@asimpleidea Might be something with your working dir. I tried and it worked for me -

Screenshot 2024-09-09 at 8 35 14 AM

@tusharmath
Copy link
Contributor

I am able to reproduce it @asimpleidea Let me take a look. Thanks for point it out.

@tusharmath tusharmath added the type: bug Something isn't working. label Sep 9, 2024
@amitksingh1490
Copy link
Collaborator

I've noticed that running the tailcall start command works when executed from a directory above the target file:

tailcall start ./examples/jsonplaceholder_script.graphql

However, when changing into the examples directory and running the command:

cd examples
tailcall start jsonplaceholder_script.graphql

it results in the error described in this issue.

@amitksingh1490
Copy link
Collaborator

/bounty 50$

Copy link

algora-pbc bot commented Sep 9, 2024

💎 $50 bounty • Tailcall Inc.

Steps to solve:

  1. Start working: Comment /attempt #2796 with your implementation plan
  2. Submit work: Create a pull request including /claim #2796 in the PR body to claim the bounty
  3. Receive payment: 100% of the bounty is received 2-5 days post-reward. Make sure you are eligible for payouts

🙏 Thank you for contributing to tailcallhq/tailcall!
🧐 Checkout our guidelines before you get started.
💵 More about our bounty program.

@asimpleidea
Copy link
Contributor Author

I am able to reproduce it @asimpleidea Let me take a look. Thanks for point it out.

Thank you! I would try to fix this myself but I discovered the project just today so I am not very familiar with its code yet

@tusharmath
Copy link
Contributor

@asimpleidea This has been fixed in the latest release please check it out — https://github.com/tailcallhq/tailcall/releases/tag/v0.111.4

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