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

Update persisted-queries.md #3616

Merged
merged 17 commits into from
Aug 30, 2021
Merged

Conversation

damikun
Copy link
Contributor

@damikun damikun commented Apr 28, 2021

Adds persisted-queries documenattion

Related converetr pull-req repo: ChilliCream/hotchocolate-examples#31

Copy link
Collaborator

@tobias-tengler tobias-tengler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for chiming in and documenting persisted queries! ❤️
I've left some feedback for you below.

@tobias-tengler tobias-tengler added the 📚 documentation This issue is about working on our documentation. label Apr 28, 2021
@damikun damikun requested a review from michaelstaib April 30, 2021 19:41
@michaelstaib
Copy link
Member

@damikun sorry for the wait. I have put that on my stack now :)

@michaelstaib michaelstaib added this to the HC-11.3.0 milestone May 6, 2021
@damikun
Copy link
Contributor Author

damikun commented Jun 4, 2021

Any plans on this or points that I can rewrite? :)

@michaelstaib
Copy link
Member

@damikun just looked at it yesterday and merge main back in so that it is technically mergeable.

.AddReadOnlyFileSystemQueryStorage("./persisted_queries");
}
```

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add another section here to show how to add the security aspect and limit the server to only allow persisted queries. I will post you some code examples.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you able to throw in an example @michaelstaib ? Thre's a TODO spot just lower. Then I think we can merge this. It'll be helpful for us at AutoGuru too, as this is next on our list for persisted queries now that we've got them all setup for the perf side of things.

@michaelstaib michaelstaib changed the base branch from main to develop June 4, 2021 07:22
@tobias-tengler
Copy link
Collaborator

I'm also going to take a look!

@michaelstaib
Copy link
Member

@tobias-tengler yes and no :D

we should handle it, further we should be able to handle multiple of them. So if multiple are in the folder we should handle them as well. Lets create an issue for that and work details out on there.

@damikun
Copy link
Contributor Author

damikun commented Jun 4, 2021

Good rewrite Tobias... You are good in understanding and writing Doc it will be better if you finish it..

@damikun damikun assigned tobias-tengler and unassigned damikun Jun 4, 2021
@tobias-tengler tobias-tengler force-pushed the dtr-adds-persisted-queries-docs branch from 8ed0478 to c6a8f80 Compare June 4, 2021 13:55
@tobias-tengler
Copy link
Collaborator

Any reason why this was retargeted to develop, while being added to the 11.3 milestone? There aren't any preview features being documented here. I think it can go straight into main...

Comment on lines 162 to 164
.UsePersistedQueryPipeline()
// ...
.UseRequest<BlockRegularQueriesMiddleware>();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is more complex than this ... you actually need to copy the full pipeline and hook into a specific place of the chain. While in your case you would still get the execution the regular request was already executed at this point.
This is why I moved this to develop so that we can introduce a new option that handles this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have most of it implemented...I will revisit it later today

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I see, works for me :)

Copy link
Collaborator

@tobias-tengler tobias-tengler Jun 28, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@michaelstaib what's the status of this? Should we track it as an issue?
I would like to get these docs in for the v11 guys: is there a good (albeit probably verbose) way to restrict execution to only persisted queries without the proposed option? If there is, I'd like to document it here and then merge it. We can then revisit the documentation, once the proposed option has been implemented in >= v12.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@michaelstaib I extracted this as an issue so we do not loose track of it: #3943

@michaelstaib michaelstaib modified the milestones: HC-11.3.0, HC-2021-06 Jun 8, 2021
@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

@benmccallum
Copy link
Collaborator

benmccallum commented Jun 30, 2021

Notes for StrawberryShake setup with persisted queries

  1. In your .graphqlrc.json, add under extensions > strawberryShake a property called requestStrategy with a value of `"PersistedQuery".
  2. Optionally set the hashAlgorithm property (by default it is "md5")
  3. Configure the output directory were the queries should be written to by adding a property to your csproj called StrawberryShake_PersistedQueryDirectory.
    1. This needs to be an absolute path
    2. Without the MSBuild property, the client generation will fallback to the default request strategy. This can be leveraged to conditionally opt-in/out of persisted queries during local development by adding a condition to the property to it is only defined when desired.
    3. Be careful not to output your persisted queries into a path picked up by your GraphQL config file's documents setting, else Strawberry Shake will consider them new queries to generate code for which will obviously conflict with the original ones.

3.3 caused me issues. GraphQLConfig isn't setup to support an array of globs, so I couldn't do an opt-in and an opt-out setup. So I tried to do a separate subfolder for my defined queries, e.g. Operations/**/*.graphql and then output to PersistedQueries, but the build was passing but not producing any generated code. 🤷🏻 I checked DotNet.Glob docs, not sure whether it's me or what, but there's probably some limitations with the current implementation of graphql config.

@tobias-tengler , not sure if you have started this anywhere, but here's my scribbles from my investigations today.

@tobias-tengler
Copy link
Collaborator

@benmccallum I won't cover this in this PR, but I derived an issue from your comment.
If you feel like it, you could also start a PR for the StrawberryShake documentation! :)

@michaelstaib
Copy link
Member

I will merge this one an we can refine in follow-up prs.

@michaelstaib michaelstaib added 🎬 ready Ready to merge and removed 👓 ready-for-review The PR is ready for review. labels Aug 30, 2021
@michaelstaib michaelstaib merged commit edd5cfe into develop Aug 30, 2021
@michaelstaib michaelstaib deleted the dtr-adds-persisted-queries-docs branch August 30, 2021 11:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📚 documentation This issue is about working on our documentation. 🎬 ready Ready to merge 🌶️ website
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants