talawa-api / Exports / utilities/TalawaGraphQLError / TalawaGraphQLError
Class: TalawaGraphQLError
utilities/TalawaGraphQLError.TalawaGraphQLError
A custom class extended from the GraphQLError class to standardize the errors returned from talawa-api's graphQL resolvers. This standardization prevents the talawa-api contributers from returning undocumented, arbitrary errors to the client applications in the graphQL query responses. This standardization also helps the client developers to know beforehand what kind of errors they can expect from talawa-api's graphQL responses, helping them design better UI experiences for user feedback.
If necessary, the localization of the error messages(i18n) can be done within the graphQL resolvers where the TalawaGraphQLError class is used.
This is the definition of a graphQL resolver for resolving the user record of the best friend of a user:-
Example
export const bestFriend = async (parent) =\> \{
const user = await dbClient.query.user.findFirst(\{
where(fields, operators) \{
return operators.eq(fields.id, parent.bestFriendId);
\}
\});
if (user === undefined) \{
throw new TalawaGraphQLError("Best friend not found", \{
code: "RESOURCE_NOT_FOUND"
\})
\}
return user;
\}
Hierarchy
-
GraphQLError
↳
TalawaGraphQLError
Table of contents
Constructors
Properties
- extensions
- locations
- message
- name
- nodes
- originalError
- path
- positions
- source
- stack
- prepareStackTrace
- stackTraceLimit
Accessors
Methods
Constructors
constructor
• new TalawaGraphQLError(message
, options
): TalawaGraphQLError
Parameters
Name | Type |
---|---|
message | string |
options | GraphQLErrorOptions & { extensions : TalawaGraphQLErrorExtensions } |
Returns
Overrides
GraphQLError.constructor
Defined in
src/utilities/TalawaGraphQLError.ts:189
Properties
extensions
• Readonly
extensions: GraphQLErrorExtensions
Extension fields to add to the formatted error.
Inherited from
GraphQLError.extensions
Defined in
node_modules/graphql/error/GraphQLError.d.ts:77
locations
• Readonly
locations: undefined
| readonly SourceLocation
[]
An array of \{ line, column \}
locations within the source GraphQL document
which correspond to this error.
Errors during validation often contain multiple locations, for example to point out two things with the same name. Errors during execution include a single location, the field which produced the error.
Enumerable, and appears in the result of JSON.stringify().
Inherited from
GraphQLError.locations
Defined in
node_modules/graphql/error/GraphQLError.d.ts:46
message
• message: string
Inherited from
GraphQLError.message
Defined in
node_modules/typescript/lib/lib.es5.d.ts:1077
name
• name: string
Inherited from
GraphQLError.name
Defined in
node_modules/typescript/lib/lib.es5.d.ts:1076
nodes
• Readonly
nodes: undefined
| readonly ASTNode
[]
An array of GraphQL AST Nodes corresponding to this error.
Inherited from
GraphQLError.nodes
Defined in
node_modules/graphql/error/GraphQLError.d.ts:57
originalError
• Readonly
originalError: undefined
| Error
The original error thrown from a field resolver during execution.
Inherited from
GraphQLError.originalError
Defined in
node_modules/graphql/error/GraphQLError.d.ts:73
path
• Readonly
path: undefined
| readonly (string
| number
)[]
An array describing the JSON-path into the execution response which corresponds to this error. Only included for errors during execution.
Enumerable, and appears in the result of JSON.stringify().
Inherited from
GraphQLError.path
Defined in
node_modules/graphql/error/GraphQLError.d.ts:53