-
-
Notifications
You must be signed in to change notification settings - Fork 519
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Angular integration #61
Comments
@Charius I personally never used Angular so I can't answer this question. |
It can't be used without React as it is a React component. But it can be used with Angular the same way as any other React component can be used with Angular, e.g. you can use import { Component } from '@angular/core';
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { Voyager } from 'graphql-voyager';
function introspectionProvider(query) {
// ...
}
@Component({
//...
})
export class VoyagerWrap {
constructor(private elRef:ElementRef) {}
ngAfterViewInit() {
ReactDOM.render(
React.createElement(
Voyager,
{ introspection: introspectionProvider }
),
this.elRef.nativeElement
);
}
} I haven't tested this code. Let us know if you manage to setup it sucessfully. As @IvanGoncharov noted above it would be great to add Angular section to README. |
@RomanGotsiy thanks, will try to integrate to simple angular project. If there will be success I'll post some code here or link to repo |
got some kind of luck, but it seems to be worker.js config required, and I'm kinda stuck here |
what the worker.js config? Does it throw any error? Maybe I can help |
the very first error message posts in console I know that I can configure |
I guess I should try add worker file in angular.json or just use require to obtain it from dist directory |
@Charius you can try adding worker to assets files in const myWorkerURI = require('file-loader!graphql-voyager/dist/voyager.worker.js');
|
Yes, |
And btw while doing all this stuff I faced with the problem from graphql/graphql-js#1344 so now project is on bleeding edge, waiting for release 😃 |
Hi, I have got stuck on the voyager.worker.js error. I am not sure where the |
As way of update I am still getting the error. I think the issue is that the voyager.worker.js file is not being copied across when I run ng serve. I tried creating a webpack.conf.js in the root folder and put the following in it with no success; module.exports = require('graphql-voyager/dist/voyager.worker.js'); If anyone has any hints it would be really appreciated. |
To help on the documentation for the Angular section I had to change the first line of @RomanGotsiy s code to the following as ElementRef needs to be imported. import { Component, ElementRef } from '@angular/core'; Still stuck on the voyager.worker bit though |
@NewToStuff Hi there! In the result about wrapper for voyager I've got something like this: The component file: import { AfterViewInit, Component, ElementRef, OnInit } from '@angular/core';
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { Voyager } from 'graphql-voyager';
import { introspectionProvider } from 'src/app/voyager/introspection-provider';
declare var require: any;
const voyagerWorkerURI = require('file-loader!graphql-voyager/dist/voyager.worker.js');
@Component({
selector: 'app-voyager-wrapper',
templateUrl: './wrapper.component.html',
styleUrls: ['./wrapper.component.scss']
})
export class WrapperComponent implements OnInit, AfterViewInit {
constructor(private elementRef: ElementRef) { }
ngOnInit() { }
ngAfterViewInit() {
ReactDOM.render(
React.createElement(
Voyager,
{
introspection: introspectionProvider,
workerURI: voyagerWorkerURI
}
),
this.elementRef.nativeElement);
}
} angular.json in projects => %project_name% => architect => build => options ...
"styles": [
"src/styles.scss",
"node_modules/graphql-voyager/dist/voyager.css"
],
|
Thanks @Charius that is really helpful. Got myself confused about how you have set up the introspectionProvider function. It is in a separate typeScript file? How does the structure look? |
@NewToStuff @Charius it is not recommended to import Just write your own, e.g.: function introspectionProvider(query) {
return fetch('<GraphQL endpoint URL here>', {
method: 'post',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({query: query}),
}).then(response => response.json());
} |
Thanks @Charius @RomanGotsiy . I am having a "brain fade" as all my application is in classes and I don't have isolated functions like this. When I am doing the import for the typeScript file which just contains the function above it is complaining that the file being imported is not a module. I will try to get the bottom of it.. |
@RomanGotsiy I've wrote own provider function, and import is from my file. Anyway thanks for clarification. |
Thanks @Charius @RomanGotsiy . I got this working in the end getting the query result from a Service I established. I ended up sorting the voyager.worker.js issue by adding the following to the assets section within angular-cli.json
Looking forward to using this awesome tool. Thanks Paul |
Is there any way to integrate this incredible tool into angular project?
I mean there is some info about integration into react project, but nothing about angular
The text was updated successfully, but these errors were encountered: