簡體   English   中英

meteor apollo graphql / sequelize緩存查詢結果,以避免多個相同的查詢

[英]meteor apollo graphql/sequelize cache query results to avoid multiple identical queries

我使用Apollo / graphql / sequelize來獲取以下關系:

我有多個標記。 每個只有一種風格。 標記可以使用相同的樣式:

Sequelize:

var Marker = db.define('markers', {
  name: {type: Sequelize.TEXT},
  idstyle: {type: Sequelize.INTEGER},
}, {timestamps: false});
const Markers = db.models.markers;

var Style = db.define('styles', {
  name: {type: Sequelize.TEXT},
  icon: {type: Sequelize.TEXT}
}, {timestamps: false});

Marker.belongsTo(Style, {foreignKey: 'idstyle'});

graphql架構:

type Marker {
    id: Int
    name: String
    style: Style
}

type Style {
    id: Int
    name: String
    icon: String
}

type Query {
  marker(limit: Int, offset: Int): [Marker]
  style(limit: Int, offset: Int): [Style]
}

解析器:

Query: {
        async marker(root, args, context) {
            return Markers.findAll({limit: args.limit, offset: args.offset});
        },
        async style(root, args, context) {
            return Styles.findAll({limit: args.limit, offset: args.offset});
        }
    },
    Marker: {
        async style(marker) {
            return marker.getStyle();
        }
    }

我意識到當我運行以下查詢時似乎沒有任何智能緩存:

query{
  marker{
    name
    style{
      name
    }
  }
}

似乎相同的樣式再次被查詢,即使它們已經作為另一個標記的結果返回。 您可以看到請求的樣式ID重復:

在此輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM