GraphQL 面试题与答案
相关差异对比
问题 21. How does GraphQL handle circular dependencies in schemas?
GraphQL allows the use of forward and backward references in a schema, but circular dependencies can be resolved using lazy loading or by using the `GraphQLObjectType` constructor to create types that reference each other.
问题 22. What is the purpose of the `__typename` field in GraphQL?
The `__typename` field in GraphQL is automatically included in every object type and represents the name of the type. It is useful for client-side caching and identifying the type of an object in a polymorphic relationship.
问题 23. Explain the concept of a union type in GraphQL.
A union type in GraphQL allows a field to return different types of objects. It is useful when a field can have multiple types, and the client needs to handle each type differently.
问题 24. What is the role of the `!` (exclamation mark) in GraphQL type definitions?
The `!` in GraphQL type definitions indicates that a field is non-nullable, meaning it must always have a value. It is used to express the presence of required data.
问题 25. How does GraphQL handle security concerns, such as denial-of-service attacks?
To mitigate security concerns, GraphQL implementations often include features like query complexity analysis and depth limiting. These measures prevent overly complex or deep queries that could lead to denial-of-service attacks.
用户评价最有帮助的内容: