GO and GraphQL Flashcards

(49 cards)

1
Q

What is Go (Golang)?

A

An open-source programming language designed for simplicity, concurrency, and performance.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the purpose of goroutines in Go?

A

To allow lightweight concurrent execution of functions.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is a channel in Go?

A

A mechanism to communicate between goroutines and synchronize their execution.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How does Go manage memory?

A

Go uses a garbage collector to automatically manage memory allocation and deallocation.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the use of defer in Go?

A

To schedule a function call to run after the function completes, often used for cleanup.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are Go interfaces?

A

A type that specifies method signatures. Types implicitly implement interfaces by defining those methods.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the zero value in Go?

A

The default value a variable has when declared without explicit initialization.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is a struct in Go?

A

A composite type that groups variables (fields) under one name.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is a Go module?

A

A collection of related Go packages with versioning, defined in a go.mod file.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is the go.mod file?

A

Defines the module’s path and its dependency versions.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is GraphQL?

A

A query language for APIs that allows clients to request exactly the data they need.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is a GraphQL schema?

A

A contract that defines types, queries, mutations, and subscriptions for a GraphQL API.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What are resolvers in GraphQL?

A

Functions that return data for specific fields in a GraphQL schema.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is a query in GraphQL?

A

A read operation that requests data from the server.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is a mutation in GraphQL?

A

A write operation used to modify server-side data.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is a subscription in GraphQL?

A

Allows clients to receive real-time updates from the server.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What is introspection in GraphQL?

A

The ability for clients to query the schema itself for available types and fields.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

What is a scalar type in GraphQL?

A

Basic data types such as Int, Float, String, Boolean, and ID.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

What is a custom scalar in GraphQL?

A

User-defined scalar types used to represent complex values like DateTime.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

What is a fragment in GraphQL?

A

Reusable selection sets that can be used across multiple queries.

21
Q

What is gqlgen?

A

A Go library for building GraphQL servers with type-safe resolvers generated from schemas.

22
Q

How does gqlgen generate code?

A

It uses a schema-first approach to generate Go code from .graphql schema files.

23
Q

Where do gqlgen resolvers live?

A

In the resolver.go file under the graph package by default.

24
Q

How do you define schema in gqlgen?

A

Using .graphql files with type, query, and mutation definitions.

25
How do you customize resolver behavior in gqlgen?
By implementing interface methods in the resolver struct.
26
What file is used to configure gqlgen?
`gqlgen.yml` defines codegen settings and resolver binding.
27
What is the role of the generated.go file?
Contains generated types and boilerplate resolver interfaces.
28
How do you run gqlgen code generation?
`go run github.com/99designs/gqlgen generate`
29
What package does gqlgen use for HTTP routing?
You can use `net/http`, `mux`, or `chi` with `handler.GraphQL()`.
30
What is context.Context used for in GraphQL resolvers?
To pass request-scoped values like auth tokens or user ID.
31
How do you handle authentication in Go GraphQL?
Using middleware to extract auth data and store it in the context.
32
How can you validate GraphQL inputs in Go?
Using custom resolvers and validation logic in input types.
33
How do you paginate data in GraphQL?
Using `first`, `after`, `last`, `before` arguments with cursors.
34
What is the N+1 problem in GraphQL?
Repeated fetching of related data leading to performance issues.
35
How do you solve the N+1 problem in Go GraphQL?
Using a data loader to batch and cache related field resolutions.
36
How can you log GraphQL queries in Go?
Using middleware or custom logger with the `handler` package.
37
How do you test GraphQL APIs in Go?
Using HTTP integration tests and mocking resolver dependencies.
38
What are some performance optimizations for Go GraphQL APIs?
Schema stitching, batched resolvers, caching, and connection pooling.
39
How do you expose metrics for a Go GraphQL API?
Using Prometheus metrics with middleware or custom handlers.
40
What is the difference between input and type in GraphQL?
`type` defines output fields, while `input` is used for arguments.
41
How do you create reusable types in GraphQL?
By defining common fields in fragments or shared input types.
42
What is non-nullable field in GraphQL?
A field marked with `!`, meaning it must not be null.
43
Can GraphQL support file uploads?
Yes, using the `multipart/form-data` spec and libraries like `graphql-upload`.
44
What is schema stitching in GraphQL?
Combining multiple schemas into a single API endpoint.
45
How do you handle versioning in GraphQL APIs?
By deprecating fields and evolving types carefully.
46
What is federation in GraphQL?
A technique for building a unified GraphQL schema from multiple services.
47
What is the @deprecated directive used for?
Marks schema fields as deprecated with a reason string.
48
What is a GraphQL playground?
An in-browser IDE for writing and testing GraphQL queries.
49
How do you handle errors in GraphQL resolvers?
By returning Go errors which GraphQL includes in the `errors` field of the response.