Relay Compiler cannot compile Graph.Cool GraphQL schemas with multiple inheritance - relayjs

I am using a generated schema from Graph.Cool that has the User type implementing two interfaces: Node and AnonymousUser. This looks like standard multiple inheritance. The Relay Compiler rejects this, however if I use an ampersand it works (implements Node & AnonymousUser vs. implements Node, AnonymousUser) and I'm not sure why. Anyone have some background on the correct syntax, or if this sounds like a bug?
COMPILER ERROR OUTPUT:
$ relay-compiler --src ./src --schema ./env/schema.graphql Error:
Error loading schema. Expected the schema to be a .graphql or a .json
file, describing your GraphQL server's API. Error detail:
GraphQLError: Syntax Error: Unexpected Name "AnonymousUser"
at syntaxError (/Users/kieran/Git/integer.systems/node_modules/graphql/error/syntaxError.js:24:10)
at unexpected (/Users/kieran/Git/integer.systems/node_modules/graphql/language/parser.js:1322:33)
at parseDefinition (/Users/kieran/Git/integer.systems/node_modules/graphql/language/parser.js:152:9)
at parseDocument (/Users/kieran/Git/integer.systems/node_modules/graphql/language/parser.js:110:22)
at parse (/Users/kieran/Git/integer.systems/node_modules/graphql/language/parser.js:38:10)
at getSchema (/Users/kieran/Git/integer.systems/node_modules/relay-compiler/bin/relay-compiler:260:28)
at /Users/kieran/Git/integer.systems/node_modules/relay-compiler/bin/relay-compiler:103:19
at Generator.next ()
at step (/Users/kieran/Git/integer.systems/node_modules/babel-runtime/helpers/asyncToGenerator.js:17:30)
at /Users/kieran/Git/integer.systems/node_modules/babel-runtime/helpers/asyncToGenerator.js:28:13
at getSchema (/Users/kieran/Git/integer.systems/node_modules/relay-compiler/bin/relay-compiler:262:12)
at /Users/kieran/Git/integer.systems/node_modules/relay-compiler/bin/relay-compiler:103:19
at Generator.next ()
at step (/Users/kieran/Git/integer.systems/node_modules/babel-runtime/helpers/asyncToGenerator.js:17:30)
at /Users/kieran/Git/integer.systems/node_modules/babel-runtime/helpers/asyncToGenerator.js:28:13
at
at process._tickCallback (internal/process/next_tick.js:160:7) error An unexpected error occurred: "Command failed. Exit code: 1
SCHEMA --------------------------------------------------
type User implements Node, AnonymousUser {
createdAt: DateTime!
email: String
id: ID!
isVerified: Boolean!
password: String
secret: String!
updatedAt: DateTime!
}
/* this works: type User implements Node **&** AnonymousUser { ... */
# An object with an ID
interface Node {
# The id of the object.
id: ID!
}
# It's an interface
interface AnonymousUser {
secret: String
isVerified: Boolean!
}

It is likely because your schema generating package is using its own out-dated graphql sub-dependency which prints the schema in a syntax that is incompatible with your current relay-compiler.
I'm not sure how exactly you generate your schema. I'm using get-graphql-schema and adding the following into my package.json solves the problem for me:
"resolutions": {
"get-graphql-schema/graphql": "^0.13.0"
}
If you're using another package, just replace get-graphql-schema with it. The idea is to get your schema generating package using newer version of graphql.

Related

Laravel 8 Docker - Many to Many Relationship not working

I need a little help understanding why my many to many relationship is not functioning. I have spent the last 1/2 day going down many rabbit holes, from trying to change the php.ini file so i would not get an xdebug error (you will see below), trying to install vim on the docker container so I could edit the php.ini, spelunking why migrations were not working ......
i installed laravel 8 using docker. I am not sure but I wonder if my problems are due to a message I am getting when I try to run anything with artisan tinker:
Xdebug: [Step Debug] Could not connect to debugging client. Tried: localhost:9003 (fallback through xdebug.client_host/xdebug.client_port) :-(
I am able to run most artisan commands, but it fails to make a migration. If i type sail php artisan make:model [tablename] -m to try to make a migration at the same time, the system successfully makes a model, but it does not make a migration. sail php artisan make migration and sail php artisan migrate also return this xdebug error along with the ERROR: 255 code.
nonetheless (whatever the hec than means), I created the tables manually, and used the artisan make:model to make the models.
I have installed laravel breeze so my User Model looks like the following. I have cut some of the interior of the class out to save space.
thank you in advance for your help.
btw, you will notice there is a return type declaration for each of the models shown below. Those are there because php storm warned me with "missing function's return type declaration.'. So I chose to add the return type declaration. I tried this same code without the return type declaration, and received the same non-results.
this is the user model
<?php
namespace App\Models;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
class User extends Authenticatable implements MustVerifyEmail
{
use Notifiable;
use SoftDeletes;
/* i have deleted some methods, etc. here */
public function people(): \Illuminate\Database\Eloquent\Relations\BelongsToMany
{
return $this->belongsToMany(Person::class, 'user_person', 'user_id', 'person_id')->withTimestamps();
}
public function family(): \Illuminate\Database\Eloquent\Relations\HasMany
{
return $this->hasMany(UserPerson::class);
}
}
this is the person model:
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Person extends Model
{
/**
* The table associated with the model.
*
* #var string
*/
protected $table = 'people';
public function users(): \Illuminate\Database\Eloquent\Relations\BelongsToMany
{
return $this->belongsToMany(User::class, 'user_person', 'person_id', 'user_id')->withTimestamps();
}
}
This is the user_person model
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class UserPerson extends Model
{
public function user(): \Illuminate\Database\Eloquent\Relations\BelongsTo
{
return $this->belongsTo(User::class);
}
}
this shows the error in php artisan tinker.
robertbryandavis#Roberts-iMac ~/D/s/rec4life (main)> sail php artisan tinker
Xdebug: [Step Debug] Could not connect to debugging client. Tried: localhost:9003 (fallback through xdebug.client_host/xdebug.client_port) :-(
Psy Shell v0.10.6 (PHP 8.0.2 — cli) by Justin Hileman
>>> $user = App\Models\User::where('email','bdavis#xxxxx.com')->get();
=> Illuminate\Database\Eloquent\Collection {#4381
all: [
App\Models\User {#4370
id: 7655,
name: "bob davis",
firstname: "bob",
lastname: "davis",
fields: taken out here for brevity
deleted_at: null,
created_at: "2019-02-07 13:43:05",
updated_at: "2021-03-18 23:56:44",
},
],
}
>>> $user->people()->get();
BadMethodCallException with message 'Method Illuminate\Database\Eloquent\Collection::people does not exist.'
>>> $user->people;
Exception with message 'Property [people] does not exist on this collection instance.'
>>> $user->family();
BadMethodCallException with message 'Method Illuminate\Database\Eloquent\Collection::family does not exist.'
>>> $user->family()->get();
BadMethodCallException with message 'Method Illuminate\Database\Eloquent\Collection::family does not exist.'
>>>
I am not sure if this is your case but I'm gonna tell you how I solved this issue, and got rid of that warning:
I solved it pointing my PHP error_log to a valid location by adding this line to my php.ini (in /etc/php/7.4/cli/php.ini):
error_log = /var/www/log/php_error.log
Change that location to any valid directory you want and try again. The warning should disappear from your output and now goes to the log file.

Circular Dependency with Nestjs Swagger 4

When I updated the #nest/swagger library to version 4, this error happened:
(node:16134) UnhandledPromiseRejectionWarning: Error: A circular dependency has been detected (property key: "customer"). Please, make sure that each side of a bidirectional relationships are using lazy resolvers ("type: () => ClassType").
at SchemaObjectFactory.createNotBuiltInTypeReference (/opt/desenvolvimento/Haizen/projectx_back/node_modules/#nestjs/swagger/dist/services/schema-object-factory.js:182:19)
at SchemaObjectFactory.mergePropertyWithMetadata (/opt/desenvolvimento/Haizen/projectx_back/node_modules/#nestjs/swagger/dist/services/schema-object-factory.js:117:25)
at /opt/desenvolvimento/Haizen/projectx_back/node_modules/#nestjs/swagger/dist/services/schema-object-factory.js:66:35
at Array.map (<anonymous>)
at SchemaObjectFactory.exploreModelSchema (/opt/desenvolvimento/Haizen/projectx_back/node_modules/#nestjs/swagger/dist/services/schema-object-factory.js:65:52)
at SchemaObjectFactory.createNotBuiltInTypeReference (/opt/desenvolvimento/Haizen/projectx_back/node_modules/#nestjs/swagger/dist/services/schema-object-factory.js:187:37)
at SchemaObjectFactory.mergePropertyWithMetadata (/opt/desenvolvimento/Haizen/projectx_back/node_modules/#nestjs/swagger/dist/services/schema-object-factory.js:117:25)
at /opt/desenvolvimento/Haizen/projectx_back/node_modules/#nestjs/swagger/dist/services/schema-object-factory.js:66:35
at Array.map (<anonymous>)
at SchemaObjectFactory.exploreModelSchema (/opt/desenvolvimento/Haizen/projectx_back/node_modules/#nestjs/swagger/dist/services/schema-object-factory.js:65:52)
My model class seems to this:
#Entity()
export class Job {
.
.
.
#ManyToOne(type => Customer, customer => customer.jobs)
#ApiProperty({ type: Customer })
customer: Customer;
}
The solution that worked for me was to declare in #ApiProperty() the type with arrow function, like below:
#Entity()
export class Job {
.
.
.
#ManyToOne(type => Customer, customer => customer.jobs)
#ApiProperty({ type: () => Customer })
customer: Customer;
}
There are at least three more cases where you get the same error message, even though they have nothing to do with bidirectional relationships:
Enum as type
Wrong:
#ApiProperty({
type: Salutation
})
public salutation: Salutation;
Correct:
#ApiProperty({
enum: Salutation
})
public salutation: Salutation;
Anonymous types
Wrong:
#ApiProperty({
})
public address: {
street: string;
houseNumber: string;
};
Correct:
#ApiProperty({
type: Address
})
public address: Address;
null
Wrong:
#ApiProperty({
description: 'This always returns null for downward compatibility'
})
public someLegacyField: null;
Correct:
#ApiProperty({
description: 'This always returns null for downward compatibility',
type: String; // needed to avoid error
})
public someLegacyField: null;
I created an issue on Github for this: https://github.com/nestjs/swagger/issues/1475
For anyone who had this problem as well, you can change the type key to the enum key on the #ApiProperty. This worked for me.
I encountered this issue when I used type interfaces on nested properties of an entity
Incorrect:
export class BookLikes {
bookLikes: {
user: User;
book: Book;
}[];
}
Nest.js recommends using classes instead - even on nested properties:
Correct:
export class BookLikes {
bookLikes: BookLike[];
}
export class BookLike {
user: User;
book: Book;
}
Take a look at this bugfix
I managed to make my enum (ProcessCat) working like this:
#ApiProperty({
enum: ProcessCat,
enumName: 'ProcessCat',
isArray: true,
})
category: ProcessCat;
And thus the NestJS compiles properly.
I've also encountered this issue recently.
In my case, I've used a few validators in the same file in my custom-validations folder. The error "A circular dependency has been detected" only appears after nest build and node dist/main.
I'm not sure if this is an issue of NestJs + Swagger after generating a build or not. Apparently, my fix was to put the validators into several files (each file contains 1 validator), it works for me.
I had this problem using Swagger Ui Cli with Webpack every time I defined an Array property. My solution was to hardcode the ApiPropterty as Array because it seems like the plugin was not picking up on it for some reason.
import { ApiProperty } from '#nestjs/swagger'
export class CreateCatDto {
#ApiProperty({ type: [String] })
kittenNames: string[]
}
Docs: https://docs.nestjs.com/openapi/types-and-parameters#arrays
Also if everything else fails rename your files to something the plugin does not pick up. Default: remove entity or dto from the name.

Variable of required type was not provided

I am attempting to create a relationship in my Neo4j database with a GraphQL mutation. I have a number of other mutations already working except this one causing problems. It looks like this:
mutation(
$id: String!,
$recipe: String!,
$date: String!
) {
CreateUserRecipeRelation(id:$id, recipe:$recipe, date:$date) {
id
recipe {
name
}
}
}
I am passing in the following set of parameters:
{"id": "google-oauth2|yyyyremovedauthstuffyyyy", "recipe": "baked spaghetti", "date": "10/10/2018"}
But the GraphQL playground throws the following error:
"Variable \"$id\" of required type \"String!\" was not provided."
In my schema.graphql file I have the following defined:
CreateUserRecipeRelation (
id: String
recipe: String
date: String
): User #cypher(statement:
"MATCH (r:Recipe{name:$recipe}), (u:User{id:$id}) CREATE (r)-[c:Created_By{date:$date}]->(u) RETURN r,c,u")
And if I run that cypher query directly in Neo4j it works just fine. In this same project I have 5 or 6 other relationship-creating mutations currently working but this one is giving me pause.
UPDATE:
This is a mutation I currently have that is working, so you can see the similarity in structure:
CreateIngredientRelation (
name: String
recipe: String
quantity: String
): Ingredient #cypher(statement:
"MATCH (r:Recipe{name:$recipe}), (i:Ingredient{name:$name}) CREATE (r)-[c:Contains{quantity:$quantity}]->(i) RETURN r,c,i")
This one works great and creates tons of relationships with the quantity attached to them. This is why I am puzzled. If they both didn't work it would be easier to try and come up with a solution I think.
#BehemothDan, how are you calling this mutation? Are you using react-apollo? If yes, Let me provide you an example of how you should be handling this.
For example, if you have a form to create this UserRecipeRelation. You have your Mutation component from react-apollo. On this Mutation you have on renderProps CreateUserRecipeRelation, that you could pass to a function on onSubmit. In this function you pass your variables:
UserRecipeRelation({ variables: { id: 'your id', recipe: 'bla bla', date: '12/12/18' } });
Hope it helps! :)

Angular library - Type 'Subject<any[]>' is not assignable to type 'Subject<any[]>'

I've been following this guide to create a custom angular library but I've hit a wall with an issue rather odd.
The idea behind exercise is simple, create a skeleton for a particular piece of functionality (in this case a staff directory) where a developer can npm install it and provide a custom data source that implements our interface.
This interface is as follows
export interface ISDDataService {
refiners: Subject<Refiner[]>;
search(queryTxt: string): Observable<Staff[]>;
refine(refiner: Refiner): Observable<Staff[]>;
}
In the library project, this skeleton is a module referenced by the root module which is set up to provide the data source which inherits the ISDDataService
#Injectable()
export class AppService implements ISDDataService {
refiners: Subject<Refiner[]>;
staff: Staff[] = [];
constructor() {
this.staff.push(<Staff>{name: 'John Doe', role: 'xyz', group: 'A Team', image: ''});
this.staff.push(<Staff>{name: 'Jane Doe', role: 'xyz', group: 'B Team', image: ''});
}
search(queryTxt: string): Observable<Staff[]> {
return Observable.of(this.staff).map(o => this.staff);
}
refine(refiner: Refiner): Observable<Staff[]> {
return ;
}
}
This is how the service is provided (app.module.ts)
providers: [
{
provide: 'ISDDataService',
useClass: AppService
}
],
The skeleton module also has the results component which uses the data source to query the data
#Component({
selector: 'app-search-results',
templateUrl: './search-results.component.html',
styleUrls: ['./search-results.component.css']
})
export class SearchResultsComponent implements OnInit {
private results: Observable<Staff[]>;
private searchField: FormControl;
constructor(#Inject('ISDDataService') private service: ISDDataService) { }
ngOnInit() {
this.searchField = new FormControl();
this.results = this.searchField.valueChanges
.debounceTime(400)
.distinctUntilChanged()
.switchMap( term => this.service.search(term));
}
}
This set up works like a charm, so proceed to package up, create a tarball and create a new "test" app so I can import the module using npm install (all these steps as per the blog post). So far so good, no errors installing the module.
the test app is just an exact replica of what I used when building the library. Same AppServices inheriting the ISDDataService, same way of providing the service and etc. I try bulding it and it all goes to hell. The error couldn't be more bizarre
ERROR in src/app/app.service.ts(9,14): error TS2420: Class 'AppService' incorrectly implements interface 'ISDDataService'.
Types of property 'refiners' are incompatible.
Type 'Subject<Refiner[]>' is not assignable to type 'Subject<Refiner[]>'. Two different types with this name exist, but they are unrelated.
Types of property 'lift' are incompatible.
Type '<R>(operator: Operator<Refiner[], R>) => Observable<R>' is not assignable to type '<R>(operator: Operator<Refiner[], R>) => Observable<R>'. Two different types with this name exist, but they are unrelated.
Types of parameters 'operator' and 'operator' are incompatible.
Type 'Operator<Refiner[], R>' is not assignable to type 'Operator<Refiner[], R>'. Two different types with this name exist, but they are unrelated.
Types of property 'call' are incompatible.
Type '(subscriber: Subscriber<R>, source: any) => TeardownLogic' is not assignable to type '(subscriber: Subscriber<R>, source: any) => TeardownLogic'. Two different types with this name exist, but they are unrelated.
Types of parameters 'subscriber' and 'subscriber' are incompatible.
Type 'Subscriber<R>' is not assignable to type 'Subscriber<R>'. Two different types with this name exist,
but they are unrelated.
Property 'isStopped' is protected but type 'Subscriber<T>' is not a class derived from 'Subscriber<T>'.
How's something like this "Subject<Refiner[]>' is not assignable to type 'Subject<Refiner[]>'" make sense!!??
I've made a couple of changes here and there but nothing works
Note, this issue is not for the refiner property only. If I remove that, it'll cascade down to the functions and so.
I'm starting to think that perhaps this approach isn't the right one... and here I thought it was pretty clean
anyhow, if anyone can give a hand would be greatly appreciated

POJO compilation fails (Algo: GBM, H2o-Version 3.8.1.3, Javac: 1.8.0_45, Mac OSX 10.11.3 / Fedora 23)

I try to locally compile a POJO of a GBM prediction model generated with H2o 3.8.1.3; I follow the instructions in the POJO class:
create a folder
Download the h2o-genmodel.jar into the folder with:
curl http://myh2oinstancesurl:myh2oinstancesport/3/h2o-genmodel.jar > h2o-genmodel.jar
Download the successfully trained GBM model named 154 into the folder with:
curl http://myh2oinstancesurl:myh2oinstancesport/3/Models/154/java > 154.java
Compile the sources in the folder with javac 1.8.0_45 under Max OSX 10.11.3 or Fedora 23:
javac -cp h2o-genmodel.jar 154.java
Result are a bunch of compilation errors:
154.java:24: error: <identifier> expected
public class 154 extends GenModel {
^
154.java:24: error: illegal start of type
public class 154 extends GenModel {
^
154.java:24: error: ';' expected
public class 154 extends GenModel {
^
154.java:25: error: illegal start of expression
public hex.ModelCategory getModelCategory() { return hex.ModelCategory.Binomial; }
^
154.java:25: error: ';' expected
public hex.ModelCategory getModelCategory() { return hex.ModelCategory.Binomial; }
^
154.java:27: error: illegal start of expression
public boolean isSupervised() { return true; }
^
154.java:27: error: ';' expected
public boolean isSupervised() { return true; }
^
154.java:28: error: illegal start of expression
public int nfeatures() { return 14; }
^
154.java:28: error: ';' expected
public int nfeatures() { return 14; }
^
154.java:29: error: illegal start of expression
public int nclasses() { return 2; }
^
...
100 errors
Is there an issue with my procedure? Or is this a bug with my setup? Is there anybody who currently can compile GBM POJOs? Thanks for your responses!
Solved: The problem was that the POJO class name obviously has to be a valid java class name; a purely numeric name is not allowed. Changing the model name resolves the issue.
[ This is not a direct answer to the question, but hopefully a helpful pointer to anyone that finds this question... ]
Since this question was asked, H2O has also added the ability to export a MOJO and use it for making predictions.
An H2O POJO is a code representation of a model, and an H2O MOJO is a data representation of a model.
A MOJO can be used in the same way as a POJO, and MOJOs do not need to be compiled (they are interpreted instead). This is especially useful for very large tree models, where trying to compile them has various technical challenges around gigabytes of code size. So in many cases, the best way to address a compilation issue is to not compile at all.
The online documentation for both H2O POJOs and MOJOs can be found here:
http://docs.h2o.ai/h2o/latest-stable/h2o-genmodel/javadoc/index.html
I hope people find this (delayed) answer helpful.

Resources