having some issues getting lighthouse and nuxtjs to work together properly.
lighthouse requires a schema.graphql
file inside the graphql directory, inside of this schema.graphql
file you have the option to either place all of your code inside of this file, or split your code into specific graphql files (this is what I did) e.g.
#import routes/*.graphql
#import posts/*.graphql
#import index/*.graphql
type Query
type Mutation
my other graphql files contain some file specific code, e.g. post.graphql
contains this
extend type Query {
posts: [Post!]! @all
}
type Post {
id:ID!,
title:String!,
content: String!
}
Now for simple queries this works fine, but when I started adding mutations things got a bit confusing.
So, I added a new file called post-mutations.graphql
inside of the graphql directory in my laravel back-end, inside of this file I extend the mutation type
extend type Mutation {
createPost(input: createIndexInput! @spread): Post @create
}
input createPostInput{
title: String!,
slug: String!
}
this works completly fine, if I go to graphql-playground and call the mutation this works.
Now when I try calling the mutation on my front end (nuxt) is where it starts to break apart, so on my front-end I have a directory called apollo, inside of this directoy is where my graphql lives. I also have a file called post-mutations.graphql
inside of this file is where I call the mutation that I created on the laravel back-end side
mutation createPost($index: createPostInput!) {
createPost(input: $index) {
title,
slug
}
}
Now the problem here is that my front-end does not have access to the createPostInput
type that I declared in my laravel app, so graphql throws an error about now knowing createPostInput
, I thought about adding the input type in my front-end but if I have to do this for every type this just seems like I'm needlessly repeating myself?
also just a sidenote, I use the graphql
extension inside of phpStorm, when I start phpStorm it asks me if I want to introspect my schema, if I do this it creates a new schema.grapgql
file at the root of my directory, inside of this file are various declarations that seem to improve IDE type completion, maybe this is something worth looking into?