Skip to content

Instantly share code, notes, and snippets.

View nilshartmann's full-sized avatar
🐿️
https://graphql.schule

Nils Hartmann nilshartmann

🐿️
https://graphql.schule
View GitHub Profile
async function loadArticle(articleId) { /* ... */ }
async function loadComments(articleId) { /* ... */ }
async function Page( {articleId} ) {
// Beide Requests starten parallel
const articlePromise = loadArticle(articleId);
const commentsPromise = loadComments(articleId);
return <React.Suspense fallback={<h1>Please wait, data is loading</h1>}>
export default undefined;
type Container<T> = {
consume: (arg: T) => void;
};
// string ist super-type von "hello" 😳
// Entspricht in C# sowas hier:
// public class Event { } // => string
// public class MouseEvent : Event { } // => "hello"
type StringType = string;
@nilshartmann
nilshartmann / DeprecationInstrumentation.java
Last active September 10, 2022 06:22
Write usage of deprecated GraphQL fields to extensions field and dump on browser console (graphql-java/Spring for GraphQL, Apollo Client)
package nh.publy.backend.util;
import graphql.ExecutionResult;
import graphql.ExecutionResultImpl;
import graphql.execution.instrumentation.InstrumentationContext;
import graphql.execution.instrumentation.InstrumentationState;
import graphql.execution.instrumentation.SimpleInstrumentation;
import graphql.execution.instrumentation.parameters.InstrumentationExecutionParameters;
import graphql.execution.instrumentation.parameters.InstrumentationFieldFetchParameters;
import graphql.schema.GraphQLFieldDefinition;
abstract class BaseError {
  private final String message;
  
  public BaseError(String message) { this.message = message; }
  
  public String getMessage() { return this.message; }
}
@nilshartmann
nilshartmann / graphql-queries-stories.md
Last active September 3, 2022 16:35
GraphQL-Query-Stories

Versuche einen Query auszuführen, der die ersten zehn Stories zurückliefert, und folgende Felder abfragt:

Id, Titel, Excerpt, Veröffentlichungsdatum, Wer hat die Story geschrieben und die jeweils ersten zehn Kommentare

query {
  stories(first: 10) {
    nodes {
      id
      title
#! /bin/zsh
#xcode-select --install
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Routing after handling an action in Redux

Note: this are simplified example, concept only, not correct syntax etc.!

Approach one: use history object in thunk action creator

// my-app-history

I recently (october 2020) evaluated MobX for a project as alternative to Redux (Redux Toolkit).

You can find my very subjective impressions below.

Redux DevTools better than MobX (for me they were more helpful when finding bugs)

Redux is more widely used than MobX

Change/Dependency tracking in MobX is powerful but not always obvious how it works (both behind the scene and in my application). If values didn't update where I expected it, finding the bug sometimes was hard

How to deal with forest/tree structures in a normalized Redux store?

A Redux-based application holds a forest-like data structure, like Folders and Documents in a file system, but with many root Folders, like this:

Folders and Documents

Example Use-Case

In a React Component, DocumentList we display all Documents (all leafs of all trees) and when clicking on one Document, we need access to the Document's root (Folder) object (to read some information from it)

@nilshartmann
nilshartmann / vs-code-vs-intellij-for-typescript-development.md
Last active March 14, 2021 17:14
Subjective opinions about VS Code and IntelliJ for TypeScript development

My very subjective impressions and opinions about VS Code and IntelliJ mainly for TypeScript development.

Note 1: This is not an objective comparison, just a list of points that I noticed when working with the two tools, and which I liked better or worse in each case.

Note 2: For IntelliJ, I used IntelliJ Ultimate Edition 2020.3

Note 3: I have used VS Code for TypeScript much longer than IntellIJ so also for this reason, this is not a "fair" comparison, because many things will turn out only in the long run, if good or bad

Note 4: many/some of the differences maybe could be adjusted by changing settings and/or keyboard shortcuts. And of course by learning the tools better.