Skip to content

Commit

Permalink
fix: ensure that apq alone (without persistent operations enabled) wo…
Browse files Browse the repository at this point in the history
…rks (#1402)
  • Loading branch information
df-wg authored Nov 27, 2024
1 parent 444fb8d commit 0681d60
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
8 changes: 8 additions & 0 deletions router-tests/automatic_persisted_queries_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ func TestAutomaticPersistedQueries(t *testing.T) {

t.Run("Sha without query fails", func(t *testing.T) {
testenv.Run(t, &testenv.Config{
RouterOptions: []core.Option{
core.WithGraphApiToken(""),
},
ApqConfig: config.AutomaticPersistedQueriesConfig{
Enabled: true,
},
Expand All @@ -36,6 +39,11 @@ func TestAutomaticPersistedQueries(t *testing.T) {

t.Run("Sha with query works", func(t *testing.T) {
testenv.Run(t, &testenv.Config{
RouterOptions: []core.Option{
// This ensures that no CDN client for persistent operations is created, so we can verify that
// APQ alone (without persistent operation support setup) works as expected.
core.WithGraphApiToken(""),
},
ApqConfig: config.AutomaticPersistedQueriesConfig{
Enabled: true,
Cache: config.AutomaticPersistedQueriesCacheConfig{
Expand Down
5 changes: 5 additions & 0 deletions router/internal/persistedoperation/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ func (c client) PersistedOperation(ctx context.Context, clientName string, sha25
return data, false, nil
}

if c.providerClient == nil {
// This can happen if we are using APQ client, without any persisted operation client. Otherwise, we should have a provider client and shouldn't reach here.
return nil, c.apqClient != nil, nil
}

content, _, err := c.providerClient.PersistedOperation(ctx, clientName, sha256Hash)
if errors.As(err, &PoNotFoundErr) && c.apqClient != nil {
// This could well be the first time a client is requesting an APQ operation and the query is attached to the request. Return without error here, and we'll verify the operation later.
Expand Down

0 comments on commit 0681d60

Please sign in to comment.