-
Notifications
You must be signed in to change notification settings - Fork 2
docs: explanation on which queries to use #101
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
1125955
Explanation document: which queries to use
theodesp f18b729
chore: update document title
theodesp 7aea062
Update docs/explanation/which-queries-to-use.md
theodesp 69b1def
Update docs/explanation/which-queries-to-use.md
theodesp 1e45820
Update docs/explanation/which-queries-to-use.md
theodesp fd02aba
Update docs/explanation/which-queries-to-use.md
theodesp 238176f
Update docs/explanation/which-queries-to-use.md
theodesp 7816600
Update docs/explanation/which-queries-to-use.md
theodesp 643023d
chore: review feedback
theodesp d61b649
Delete docs/explanation/which-queries-to-use.md
moonmeister File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| # Which WPGraphQL endpoints to use: /graphql vs ?graphql | ||
|
|
||
| WPGraphQL exposes a GraphQL endpoint that developers can use to interact with the WordPress backend and retrieve data. | ||
|
|
||
| The plugin provides two primary ways to interact with this API: | ||
|
|
||
| 1. The pretty URL endpoint `/graphql` | ||
| 2. The query-string-based endpoint `/index.php?graphql` | ||
|
|
||
| Both serve the same purpose of providing access to the GraphQL API, but they function slightly differently. | ||
|
|
||
| ## The default `/graphql` endpoint | ||
|
|
||
| The `/graphql` default endpoint is the preferred choice for most users because it is easy to read, share, and remember. | ||
|
|
||
| WPGraphQL allows you to customize the `/graphql` endpoint using a filter. If you'd like to change the endpoint to something more specific to your site, you can do so with a simple code snippet. | ||
|
|
||
| ```php | ||
| function my_new_graphql_endpoint() { | ||
| return 'my_endpoint'; | ||
| }; | ||
|
|
||
| add_filter( 'graphql_endpoint', 'my_new_graphql_endpoint' ); | ||
| ``` | ||
| This code would change the default `/graphql` endpoint to `/my_endpoint`. | ||
|
|
||
| ## The query string endpoint: `/index.php?graphql` | ||
|
|
||
| WPGraphQL also provides an alternative endpoint that works even if pretty permalinks are not enabled. This endpoint is based on the standard WordPress `index.php` file, with a query string parameter: | ||
theodesp marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ```php | ||
| /index.php?graphql | ||
| ``` | ||
theodesp marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| This query-string endpoint serves as a fallback for WordPress sites that do not have pretty permalinks enabled. If a site is running with the default URL structure (e.g., `example.com/?p=123`), the `/graphql` pretty URL might not work. In this case, `/index.php?graphql` can be used to access the GraphQL API. | ||
|
|
||
| ## Which one should you use and why? | ||
|
|
||
theodesp marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| If you have pretty permalinks enabled, it’s best to use the clean `/graphql` endpoint. | ||
theodesp marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| WordPress is very flexible with URL routing, and even if your permalinks are enabled, the URL `index.php?graphql` is still valid. In this case, WordPress will handle the request through `index.php`, with the graphql query parameter routing it to WPGraphQL. | ||
theodesp marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| If there is any issue with the `/graphql` endpoint (perhaps due to rewrite rules, .htaccess configurations, or plugin conflicts), the `/index.php?graphql` endpoint can be a quick alternative to ensure your requests are still processed correctly. | ||
theodesp marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.