问题描述
看起来我的公司将从阿波罗客户端进行持久查询,如下所述: https://dev-blog.apollodata.com/persisted-graphql-ceries-with-queries-with-apollo-client-client-119fd7e6bba5
在本文中,提到服务器上的中间件需要做些事情.我找不到有关用石墨烯-django更改的信息.
谁能提供任何建议?
罗伯特
推荐答案
持续存在的查询不是GraphQL规格的一部分,因此可以以多种方式实现.以下是您可能想在服务器上执行此操作的一些示例:
提取查询
截至撰写本文时,您可以与Relay Modern,Apolo客户端等提取静态查询.它们都以相似的方式工作,因此我将使用 apollo persistgraphql 作为示例.在您的构建中,您需要在SRC目录上运行persistgraphql命令以提取静态查询.此命令的结果将是一个填充有查询的JSON文件,作为字符串和一个数字为值.
{ " { author { firstName lastName } } ": 9, " query otherQuery { person { firstName lastName } } ": 10 }
使用提取的查询
从这里,您有一些选择.一旦您的服务器了解所有可能的查询,它就可以为JSON文件中提供的值提供一个接口,也可以将其查找的查询列表.如果您的服务器仅提供值的接口(myserver/api/9,myserver/api/10在上面的示例中),则需要确保客户端应用程序映射它是通过使其消耗相同JSON文件来查询对ID的商定的查询.另外,您可以使用该文件来防止在不以任何方式修改客户端的情况下执行意外查询.
您如何专门设置服务器以消耗此JSON文件取决于您.有些人会预先执行已知查询集,并将其放入REDIS等快速数据存储中.有些人严格使用它来防止未经授权的查询.至于Django-Graphene的完成方式,我知道没有开箱即用的解决方案,但是在上面的一家中消耗提取的钥匙/价值商店,应该为您的团队提供一堆好的优质选项.
其他推荐答案
您可以检查持续的查询django
https://github.com/flavors/django-gravors/django-graphql-persist
问题描述
It looks like my company is going to move forward with Persisted Queries from the Apollo Client, as is discussed here: https://dev-blog.apollodata.com/persisted-graphql-queries-with-apollo-client-119fd7e6bba5
In this article there is mention that something needs to be done to the Middleware on the server. I have been unable to find any information as to what needs to be changed with Graphene-Django.
Can anyone provide any advice?
Robert
推荐答案
Persisted queries are not a part of the GraphQL spec and, as such, can be implemented in a wide variety of ways. Here are a few examples of how you might want to do this on your server:
Extract Queries
As of the time of this writing, you can extract static queries with Relay Modern, the Apolo Client, and others. They all work in similar ways, so I'll use Apollo PersistGraphQL as an example. In your build, you will need to run the persistgraphql command over your src directory to extract your static queries. The result of this command will be a JSON file filled with queries, as strings, and a number as the value.
{ " { author { firstName lastName } } ": 9, " query otherQuery { person { firstName lastName } } ": 10 }
Use extracted queries
From here, you have a few options. Once your server is aware of all possible queries, it can either provide an interface to the values provided in the JSON file, or it can whitelist the queries it knows about. If your server only provides an interface to the values (myserver/api/9, myserver/api/10 in the example above), you would need to make sure that your client app maps it's queries to those agreed on IDs by having it consume the same JSON file. Alternatively, you could use that file to prevent unexpected queries from being executed without modifying the client in any way.
How you specifically set up your server to consume this JSON file is up to you. Some people will pre-execute the set of known queries and put them into a fast data-store like Redis. Some people use it strictly for preventing unauthorized queries. As far as how this is done with Django-Graphene, there is no out-of-the-box solution that I'm aware of but consuming an extracted key/value store like the one above should provide your team with a bunch of good options.
其他推荐答案
You can check Persisted queries for Graphene Django