简体   繁体   English

meteor apollo graphql / sequelize缓存查询结果,以避免多个相同的查询

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

I use Apollo/graphql/sequelize to grab the following relation: 我使用Apollo / graphql / sequelize来获取以下关系:

I have multiple markers. 我有多个标记。 Each has only one Style. 每个只有一种风格。 Markers may use the same styles: 标记可以使用相同的样式:

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 schema: 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]
}

resolvers: 解析器:

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();
        }
    }

I realized that there does not seem to be any intelligent caching when I run the following query: 我意识到当我运行以下查询时似乎没有任何智能缓存:

query{
  marker{
    name
    style{
      name
    }
  }
}

It seems that the same styles are queried again even when they have already been returned as a result for another marker. 似乎相同的样式再次被查询,即使它们已经作为另一个标记的结果返回。 You can see that the requested style ids repeat: 您可以看到请求的样式ID重复:

在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM