Skip to content

Empty response cache with Cloudflare workers and KV #5171

Open
@smakhtin

Description

@smakhtin

Trying to use response caching with Cloudflare workers and KV. Cache entries are created in KV, but cache never hit and in Cloudflare console i can see that cached data is empty json ({}).

Config:

sources:
  - name: TheGraph
    handler:
      graphql:
        endpoint: '{{&GRAPHQL_ENDPOINT}}'
  - name: Pinata
    handler:
      jsonSchema:
        endpoint: 'https://sni.mypinata.cloud/'
        operations:
          - type: Query
            field: ipfsMetadata
            path: /ipfs/{args.cid}
            method: GET
            responseSchema: ./json-schemas/metadata.json
        operationHeaders:
          x-pinata-gateway-token: '{{&PINATA_TOKEN}}'
    transforms:
      - resolversComposition:
          mode: bare
          compositions:
            - resolver: 'Query.ipfsMetadata'
              composer: './middleware/getCid.ts'
additionalTypeDefs: |
  extend type SNI {
    metadata: Identifier_Token_Metadata
  }
additionalResolvers:
  - targetTypeName: SNI
    targetFieldName: metadata
    sourceName: Pinata
    sourceTypeName: Query
    sourceFieldName: ipfsMetadata
    requiredSelectionSet: |
      {
        tokenURI
      }
    sourceArgs:
      cid: '{root.tokenURI}'
plugins:
  - responseCache:
      includeExtensionMetadata: true
cache:
  cfwKv:
    namespace: MESH

Deployed gateway - https://gateway-staging.sovereignnature.ch/graphql.

Example response:

{
	"data": {
		"sni": {
			"id": "0x0"
		}
	},
	"extensions": {
		"responseCache": {
			"hit": false,
			"didCache": true,
			"ttl": null
		}
	}
}

Cloudflare console:
image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions