gatsby-remark-prismjs 不适用于我的设置。
我正在尝试突出显示 javascript 和 swift 等代码。
我的博客内容来自 wordpress.com
这是我的 gatsby.config.js
,
{
resolve: `gatsby-transformer-remark`,
options: {
plugins: [
{
resolve: `gatsby-remark-prismjs`,
options: {
// Class prefix for <pre> tags containing syntax highlighting;
// defaults to 'language-' (eg <pre class="language-js">).
// If your site loads Prism into the browser at runtime,
// (eg for use with libraries like react-live),
// you may use this to prevent Prism from re-processing syntax.
// This is an uncommon use-case though;
// If you're …Run Code Online (Sandbox Code Playgroud) 所以我想弄清楚为什么我的 Query 最终是:
{
"errors": [
{
"message": "Cannot return null for non-nullable field Message.sender.",
}
...
}
Run Code Online (Sandbox Code Playgroud)
这是我的实体
@Entity()
export class Message extends BaseEntity {
@PrimaryGeneratedColumn("uuid")
id: string;
@Column("text")
content: string;
@CreateDateColumn()
created_at: string;
// @ts-ignore
@ManyToOne(type => User, user => user.messages)
sender: User;
}
Run Code Online (Sandbox Code Playgroud)
还有我的解析器:
allMessagesOfProject: async (_, { projectId }, __) => {
const project = await Project.findOne({
relations: ["messages"],
where: { id: projectId }
});
if (project) {
const messages = project.messages;
return messages.reverse();
}
return …Run Code Online (Sandbox Code Playgroud) 目前,我正在抛出RuntimeException's 以返回 GraphQL 验证错误。它工作得非常好,除了它会在我的日志中抛出带有大量堆栈跟踪的可怕错误。
在这里您可以看到我正在检查提交的新用户注册变更,以确保密码彼此匹配并且电子邮件地址尚未使用。
在 GraphQL SPQR Spring Boot Starter 中执行此操作的正确方法是什么。
@GraphQLMutation (name="register")
public User register(@GraphQLArgument(name="firstname") String firstname, @GraphQLArgument(name="lastname") String lastname, @GraphQLArgument(name="email") String email, @GraphQLArgument(name="msisdn") String msisdn, @GraphQLArgument(name="password") String password, @GraphQLArgument (name="confirmPassword") String confirmPassword) {
if (userRepo.findByEmail(email) != null) {
throw new RuntimeException("User already exists");
}
if (!password.equals(confirmPassword)) {
throw new RuntimeException("Passwords do not match");
}
User newUser = new User();
//...
return userRepo.save(newUser);
}
Run Code Online (Sandbox Code Playgroud) 我设法得到了一个运行 typescript 和 apollo graphql 的 nuxt.js + nest.js。为了测试 graphql 是否有效,我使用了这个示例中的文件,并在 nuxt.js 页面中添加了一个按钮(on:click -> 通过 graphql 加载所有猫)。
一切正常,阅读和写作。
问题是在通过操场进行更改或使用其他 graphql 数据重新启动 nest.js 服务器后,nuxt.js 页面显示旧数据(单击时)。我必须在浏览器中重新加载整个页面,才能让 Apollo-Client 获取新数据。
我尝试向 nuxt.config.ts 添加“无缓存”标志和“仅网络”标志,但没有成功:
apollo: {
defaultOptions: {
$query: {
loadingKey: 'loading',
fetchPolicy: 'no-cache'
}
},
clientConfigs: {
default: {
httpEndpoint: 'http://localhost:4000/graphql',
wsEndpoint: 'ws://localhost:4000/graphql'
}
}
}
Run Code Online (Sandbox Code Playgroud)
获取猫的函数:
private getCats() {
this.$apollo.query({ query: GET_CATS_QUERY }).then((res:any) => {
alert(JSON.stringify(res.data, null, 0));
});
}
Run Code Online (Sandbox Code Playgroud)
如何禁用缓存或是否有其他解决方案?
我想将 HTTP POST 值直接作为 JSON 发送到已在我的 GraphQL Mutation 中声明的 addBook 解析器。
但是,我见过(并证明)的示例使用从 JSON 到 SDL 的参数序列化或在 SDL 中重新声明变量以从查询变量进行绑定。
这两种方法都没有意义,因为 addBook 突变已经声明了所有参数和验证。使用这些方法将导致必须创建、调试和维护不必要的查询序列化逻辑。
我在浏览器中构造了格式良好(模式编辑和验证)的 JSON,它符合声明的 GraphQLObjectType 的数据。
谁能解释在针对突变解析器发布时如何避免这种不必要的重新序列化或重复?
我一直在尝试使用多种方法将 JSON 数据结构映射到 addBook 突变,但找不到简单发送 JSON 的示例,以便将属性名称绑定到 addBook 参数名称,而没有明显毫无意义的重新序列化或样板。
https://github.com/cefn/graphql-gist/tree/master/mutation-map 上的源代码是一个最小的可重现示例,它演示了该问题。它有一个 addBook 解析器,它已经定义了参数名称、类型和可空性。我找不到使用 JSON 来简单地针对 addBook POST 参数的方法。
我使用 GraphiQL 作为 HTTP POST 值的参考实现。
我可以编写代码将 JSON 序列化为 SDL。它最终看起来像这样,它通过 GraphiQL 工作:
mutation {addBook(id:"4", name:"Education Course Guide", genre: "Education"){
id
}}
Run Code Online (Sandbox Code Playgroud)
或者,我可以编写代码将 addBook 的每个参数显式别名为不同的查询,然后允许我将值作为 JSON 查询变量发布,也通过 GraphiQL 证明:
mutation doAdd($id: String, $name: String!, $genre: String){ …Run Code Online (Sandbox Code Playgroud) 我在标准模块中有以下 GraphQL 服务器调用:
export default () => {
return graphqlHTTP({
schema: schema,
graphiql: true,
pretty: true,
formatError: error => ({
message: error.message,
locations: error.locations,
stack: error.stack,
path: error.path
})
});
};
Run Code Online (Sandbox Code Playgroud)
与护照一起使用:
app.use(
"/graphql",
passport.authenticate("jwt", { session: false }),
appGraphQL()
);
Run Code Online (Sandbox Code Playgroud)
一切都是工作文件。Passport 扩展了 myreq以获取在我的 GraphQL 调用查询或更改时使用的已记录用户对象:
...
resolve(source, args, context) {
console.log("CURRENT USER OBJECT")
console.log(context.user)
...
Run Code Online (Sandbox Code Playgroud)
一切都很好。
现在我需要扩展我的上下文以添加一些自定义解析器,所以我的第一次尝试是:
export default () => {
return graphqlHTTP({
schema: schema,
graphiql: true,
pretty: true,
context: resolvers,
formatError: error => ({
message: …Run Code Online (Sandbox Code Playgroud) 我知道这已经被问了几个的时间之前,但我发现没有明确的解决方案,这是否是可能的GraphQL。我强烈认为这应该是可能的,因为它应该相对容易实现,因为 GraphQL 查询在 Apollo 中按顺序运行。
我有一种情况,我首先在客户端上执行 GraphQL 突变,然后在执行使用上一个查询结果的查询之后立即执行。这会导致等待服务器响应两个请求的响应时间过长。请求如下所示:
mutation createWebSession($authId: ID!) {
webSession: createWebSession(authId: $authId) {
token
userId
}
}
query listUserPaymentMethods($userId: ID!) {
userPaymentMethods: paymentMethods(userId: $userId) {
id
}
}
Run Code Online (Sandbox Code Playgroud)
我知道一种避免两次往返服务器的简单创可贴解决方案是创建一个新的单一 GraphQL 突变端点,该端点在后端执行这两项服务。但这似乎违背了编写模块化、可重用 GraphQL 端点的目的。因此,我很好奇是否有人知道 Apollo GraphQL 是否支持一种更简洁的方式来链接 2 个请求,其中前一个请求的结果可作为输入提供给下一个请求。
任何帮助将不胜感激,谢谢。
我定义了以下 gQL,
import gql from 'graphql-tag'
const SIGN_UP_QUERY = gql`
query {
signUpForm @client {
firstName
email
password
}
}
`
Run Code Online (Sandbox Code Playgroud)
我将它与 react-apollo 查询一起使用
<Query query={SIGN_UP_QUERY}>
{({
data: {
signUpForm: { firstName }
},
loading
}) => { ...... }}
</Query>
Run Code Online (Sandbox Code Playgroud)
有了这个我得到一个错误 Cannot read property 'firstName' of undefined
我在这里做错了什么?
这个函数将返回所有用户而不是给定的用户名,我怎么能做对?还有更好的 Python GraphQL 客户端吗?gql 就这么简单,没有多少文件可以检查。
def fetch_user(username):
query = gql("""
query getUser($username: String) {
user(
where: { name: { _eq: $username } }
) {
id
name
}
}
""")
result = client.execute(query)
Run Code Online (Sandbox Code Playgroud) 在 Laravel Lighthouse GraphQL 中,如何从中间“数据透视”表中检索信息?
假设我有一个属于belongsToMany关系的用户和角色:
type User {
roles: [Role!]! @belongsToMany
}
type Role {
users: [User!]! @belongsToMany
}
type Query {
user(id: ID! @eq): User @find
role(id: ID! @eq): Role @find
}
Run Code Online (Sandbox Code Playgroud)
并且还假设中间表User_Role包含列“created_at”和“tag_id”。
我将如何在查询中包含“created_at”?
我将如何获得tag_id引用的标签?
graphql ×10
apollo ×2
reactjs ×2
express ×1
gatsby ×1
graphql-spqr ×1
http ×1
java ×1
javascript ×1
json ×1
laravel ×1
mutation ×1
node.js ×1
nuxt.js ×1
passport.js ×1
pivot-table ×1
post ×1
react-apollo ×1
spring-boot ×1
typeorm ×1
validation ×1