Skip to content

Instantly share code, notes, and snippets.

@shark-h
Created September 4, 2019 10:30
Show Gist options
  • Save shark-h/bb6c0e7703e4564a3050d5e984b1be23 to your computer and use it in GitHub Desktop.
Save shark-h/bb6c0e7703e4564a3050d5e984b1be23 to your computer and use it in GitHub Desktop.
class MainApp extends StatelessWidget {
final FirebaseUser user;
final token;
const MainApp({Key key, this.token, this.user}) : super(key: key);
@override
Widget build(BuildContext context) {
final HttpLink httpLink = HttpLink(
uri: '<your-graphql-endpoint>',
);
final WebSocketLink websocketLink = WebSocketLink(
url: 'wss://<your-graphql-endpoint>,
config: SocketClientConfig(
autoReconnect: true,
inactivityTimeout: Duration(seconds: 30),
),
);
final AuthLink authLink = AuthLink(
getToken: () async => 'Bearer ' + token,
);
final Link link = authLink.concat(httpLink as Link).concat(websocketLink);
ValueNotifier<GraphQLClient> client = ValueNotifier(
GraphQLClient(
cache: InMemoryCache(),
link: link,
),
);
return GraphQLProvider(
client: client,
child: MaterialApp(
theme: ThemeData(primarySwatch: Colors.red),
home: Menu(
user: user,
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment