graphql

Paginating GatsbyJS pages when filtering Wordpress posts by category

旧巷老猫 提交于 2021-02-19 07:36:07
问题 Can anyone shed some insight on how I would go about paginating pages in Gatsby when filtering Wordpress posts by category? For context, my gatsby-node file: const path = require('path') module.exports.createPages = async ({ graphql, actions }) => { // import { paginate } from 'gatsby-awesome-pagination'; const { createPage } = actions const blogPostTemplate = path.resolve('./src/templates/blog-post.js') const blogCategoryFilter = path.resolve('./src/templates/blog-filter-category.js') const

人人都是 API 设计者:我对 RESTful API、GraphQL、RPC API 的思考

烂漫一生 提交于 2021-02-19 03:35:02
有一段时间没怎么写文章了,今天提笔写一篇自己对 API 设计的思考。首先,为什么写这个话题呢?其一,我阅读了《阿里研究员谷朴:API 设计最佳实践的思考》一文后受益良多,前两天并转载了这篇文章也引发了广大读者的兴趣,我觉得我应该把我自己的思考整理成文与大家一起分享与碰撞。其二,我觉得我针对这个话题,可以半个小时之内搞定,争取在 1 点前关灯睡觉,哈哈。 现在,我们来一起探讨 API 的设计之道。我会抛出几个观点,欢迎探讨。 一、定义好的规范,已经成功了一大半 通常情况下,规范就是大家约定俗成的标准,如果大家都遵守这套标准,那么自然沟通成本大大降低。例如,大家都希望从阿里的规范上面学习,在自己的业务中也定义几个领域模型:VO、BO、DO、DTO。其中,DO(Data Object)与数据库表结构一一对应,通过 DAO 层向上传输数据源对象。而 DTO(Data Transfer Object)是远程调用对象,它是 RPC 服务提供的领域模型。对于 BO(Business Object),它是业务逻辑层封装业务逻辑的对象,一般情况下,它是聚合了多个数据源的复合对象。那么,VO(View Object) 通常是请求处理层传输的对象,它通过 Spring 框架的转换后,往往是一个 JSON 对象。 事实上,阿里这种复杂的业务中如果不划分清楚 DO、BO、DTO、VO 的领域模型

How to unit test GraphQL queries in Gatsby

人盡茶涼 提交于 2021-02-19 03:14:45
问题 I'm using Gatsby and Jest for testing. By default Gatsby handles the GraphQL data fetching, and from what I've found it doesn't provide any solution for testing its GraphQL queries in unit tests. Is there a way to do this? Right now I'm just mocking the queries the test the component itself, but I want to be able to test queries work without manually doing so in GraphiQL. Here's what my code looks like: PageContent.jsx import PropTypes from 'prop-types'; import React from 'react'; const

How to unit test GraphQL queries in Gatsby

梦想与她 提交于 2021-02-19 03:13:55
问题 I'm using Gatsby and Jest for testing. By default Gatsby handles the GraphQL data fetching, and from what I've found it doesn't provide any solution for testing its GraphQL queries in unit tests. Is there a way to do this? Right now I'm just mocking the queries the test the component itself, but I want to be able to test queries work without manually doing so in GraphiQL. Here's what my code looks like: PageContent.jsx import PropTypes from 'prop-types'; import React from 'react'; const

Best way to handle one-to-many with type-graphql typeorm and dataloader

我怕爱的太早我们不能终老 提交于 2021-02-19 01:38:08
问题 I'm trying to figure out the best way to handle a one-to-many relationship using type-graphql and typeorm with a postgresql db (using apollo server with express). I have a user table which has a one-to-many relation with a courses table. The way I am currently handling this is to use the @RelationId field to create a column of userCourseIds and then using @FieldResolver with dataloader to batch fetch the courses that belong to that user(s). My issue is that with the @RelationId field, a

Unable to find any GraphQL type definitions for the following pointers: src/**/*.graphql

倾然丶 夕夏残阳落幕 提交于 2021-02-18 22:33:09
问题 I am using the @graphql-codegen/cli tool to generate typescript types out of my graphql server. Here is my codegen.yml content: overwrite: true schema: "http://localhost:3001/graphql" documents: "src/**/*.graphql" generates: src/generated/graphql.tsx: plugins: - "typescript" - "typescript-operations" - "typescript-react-apollo" ./graphql.schema.json: plugins: - "introspection" Here is the package.json script I use to generate my types ( yarn schema ): "schema": "graphql-codegen --config

compose not exported from react-apollo

佐手、 提交于 2021-02-18 22:15:26
问题 I'm following a graphql tutorial on youtube (https://www.youtube.com/watch?v=ed8SzALpx1Q at about 3hr 16min) and part of it uses compose from "react-apollo". However, I'm getting an error because the new version of react-apollo does not export this. I read online that I need to replace import { compose } from "react-apollo" with import { compose } from "recompose" but doing that produces the error TypeError: Cannot read property 'loading' of undefined I've also read that I should replace the

Duplicate object types in Apollo GraphQL for Android

情到浓时终转凉″ 提交于 2021-02-18 21:58:50
问题 On my project GraphQL schema the object AllowedPeriod (it's just two fields startsAt/endsAt) can arrive inside different objects of the graph. When generating queries, apollo is creating a new type for every <parent_object>.AllowedPeriod For example, in the GetDevicesQuery , the AllowedPeriod can be inside devices , actions or group , hence generating the following classes. GetDevicesQuery.AllowedPeriod GetDevicesQuery.AllowedPeriod1 GetDevicesQuery.AllowedPeriod2 Is there a way to tell

Dynamic routes nextjs with status code 404

梦想的初衷 提交于 2021-02-18 18:57:42
问题 I have a project with dynamic route like /[category]/[product] . After a client-side request via useRouter to graphql for example /hatchback/nissan/ returns a product with a code of 200, but if I make a request to /hatchback/nissan111/ , I get an error because no such route exists and its response code still of 200 instead of 404. How can I check if a route exists and return a 404 status code during the component mount stage? I use SSR to achive this 来源: https://stackoverflow.com/questions

Dynamic routes nextjs with status code 404

帅比萌擦擦* 提交于 2021-02-18 18:56:35
问题 I have a project with dynamic route like /[category]/[product] . After a client-side request via useRouter to graphql for example /hatchback/nissan/ returns a product with a code of 200, but if I make a request to /hatchback/nissan111/ , I get an error because no such route exists and its response code still of 200 instead of 404. How can I check if a route exists and return a 404 status code during the component mount stage? I use SSR to achive this 来源: https://stackoverflow.com/questions