Created
September 4, 2019 10:30
-
-
Save shark-h/bb6c0e7703e4564a3050d5e984b1be23 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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