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

Add automatically-verified working examples #668

Merged
merged 1 commit into from
Apr 19, 2024

Conversation

shish
Copy link
Contributor

@shish shish commented Mar 22, 2024

Add "no framework" example to examples folder

Having an example as actual code rather than as out-of-context snippets inside a text file means that we can run the code, and ensure that it actually works

Submitting mostly for discussion to see if people like this idea

TODO:

  • have a github action which runs the code and ensures that the "hello world" query works (thus ensuring that the example code is correct)
  • install graphqlite from parent folder instead of downloading the published 6.X (thus ensuring that the example is always in-sync with the library it is an example of)
  • update the documentation to reference the files in this repository, rather than embedding hard-coded out-of-context snippets into the .mdx files (thus ensuring that the documentation stays in-sync with the known-good example code)

@codecov-commenter
Copy link

codecov-commenter commented Mar 22, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.31%. Comparing base (53f9d49) to head (e3d5d1a).
Report is 82 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff              @@
##             master     #668      +/-   ##
============================================
- Coverage     95.72%   95.31%   -0.41%     
- Complexity     1773     1809      +36     
============================================
  Files           154      171      +17     
  Lines          4586     4783     +197     
============================================
+ Hits           4390     4559     +169     
- Misses          196      224      +28     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@oojacoboo
Copy link
Collaborator

oojacoboo commented Mar 23, 2024

@shish I think this is a reasonable solution. However, it's not going to remain accurate unless there are tests for it.

We should probably update the .github/workflows/continuous_integration.yml to include a step that can execute each of the examples and assert the results.

Another alternative would be adding a PHPUnit test that executes the examples.

Edit: Glanced over your todo list - agreed.

Let's prioritize the testing setup, as that'll help with assisting on feedback and contributions.

@oojacoboo oojacoboo marked this pull request as draft April 3, 2024 06:00
@oojacoboo
Copy link
Collaborator

Converted this to a draft until the TODO items are completed.

@shish shish force-pushed the pr668 branch 8 times, most recently from fac2b9b to d7d3559 Compare April 3, 2024 23:31
@shish
Copy link
Contributor Author

shish commented Apr 3, 2024

For reasons I am struggling to figure out, this runs fine on my dev machine but fails in github T_T

cd examples/no-framework
composer install --no-interaction --no-progress --prefer-dist
php -S localhost:8080 &
sleep 3
curl --silent -X POST -H "Content-Type: application/json" \
            -d '{"query":"{ hello(name: \"World\") }"}' \
            http://localhost:8080/graphql

Local output:

{"data":{"hello":"Hello World"}}

Output when run on github:

{"errors":[{"message":"Cannot query field \"hello\" on type \"Query\".","locations":[{"line":1,"column":3}]}]}

Interestingly when I run the published [email protected] it works and [email protected] gives the same error as we see on github...

@oojacoboo
Copy link
Collaborator

oojacoboo commented Apr 4, 2024

For reasons I am struggling to figure out, this runs fine on my dev machine but fails in github T_T

cd examples/no-framework
composer install --no-interaction --no-progress --prefer-dist
php -S localhost:8080 &
sleep 3
curl --silent -X POST -H "Content-Type: application/json" \
            -d '{"query":"{ hello(name: \"World\") }"}' \
            http://localhost:8080/graphql

Local output:

{"data":{"hello":"Hello World"}}

Output when run on github:

{"errors":[{"message":"Cannot query field \"hello\" on type \"Query\".","locations":[{"line":1,"column":3}]}]}

Interestingly when I run the published [email protected] it works and [email protected] gives the same error as we see on github...

Version 7 uses https://github.com/alekitto/class-finder, and master will now look to the Composer autoload file for namespaces, by default (will be 7.1).

@shish
Copy link
Contributor Author

shish commented Apr 4, 2024

Any idea what needs to change in the code to make it work? If you download this PR and run the test steps from the github action, does it work for you? Any idea why it works on my laptop but not on github?

FYI, I don't have a "known-good" graphqlite setup that I can compare against, so I'm still not sure if my example code is even supposed to work the way it has been written - is it my code that's broken or something wrong with the framework? Without having a working example that I can compare against, I am debugging blind and I don't even know what direction I'm supposed to be going in 😓

(I'm not actually a graphqlite user, just somebody who found the docs so frustrating that it was easier to write my own schema-generator from scratch -- I would like to deprecate my own and use graphqlite, but I can't do that if I can't figure out why graphqlite isn't working, and it's hard to figure out why it's not working if there isn't a working example to compare against 😅 )

@oojacoboo
Copy link
Collaborator

oojacoboo commented Apr 12, 2024

@shish see #679 - might be the issue you're having? Also, it'd be nice if we could merge all these PRs you have together. That'd help with getting this merged.

Having an example as actual code rather than as out-of-context snippets inside a text file means that we can run the code, and ensure that it actually works

Submitting mostly for discussion to see if people like this idea

TODO:
- have a github action which runs the code and ensures that the "hello world" query works (thus ensuring that the example code is correct)
- install graphqlite from parent folder instead of downloading the published 6.X (thus ensuring that the example is always in-sync with the library it is an example of)
- update the documentation to reference the files in this repository, rather than embedding hard-coded out-of-context snippets into the .mdx files (thus ensuring that the documentation stays in-sync with the known-good example code)
@shish shish force-pushed the pr668 branch 2 times, most recently from 67e72e1 to 521bce9 Compare April 17, 2024 14:58
@shish shish changed the title Add "no framework" example to examples folder Add automatically-verified working examples Apr 17, 2024
@shish
Copy link
Contributor Author

shish commented Apr 17, 2024

@shish see #679 - might be the issue you're having?

So that fixed the no-framework example, but it didn't fix the psr-15 example, which is having the same error T_T

Also, it'd be nice if we could merge all these PRs you have together. That'd help with getting this merged.

The "automatically test examples as part of github actions" and "the no-framework example" are now working. Since the psr-15 example is broken for seemingly unrelated examples, I wonder if we could merge this PR as-is, and then rebase the other PR on top of it to try and debug what's wrong with that one?

@shish shish marked this pull request as ready for review April 17, 2024 15:41
@oojacoboo oojacoboo merged commit 1a8dd39 into thecodingmachine:master Apr 19, 2024
17 checks passed
@shish shish deleted the pr668 branch April 21, 2024 20:32
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

Successfully merging this pull request may close these issues.

3 participants