GithubHelp home page GithubHelp logo

novacloudcz / graphql-orm Goto Github PK

View Code? Open in Web Editor NEW
81.0 81.0 7.0 360 KB

Golang GraphQL API generator using gqlgen and gorm

License: MIT License

Go 73.58% Gherkin 24.74% Makefile 1.35% Dockerfile 0.33%
apollo-federation generator golang gorm gqlgen graphql graphql-orm orm

graphql-orm's People

Contributors

jakubknejzlik avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

graphql-orm's Issues

How to extend the custom method?

Hello:
I would like to ask, after the generated code, I want to expand a user login method, how to operate, is there an example?
Or if you want to extend other custom methods, what should you do?
Thanks!

init failed

Steps

  • mkdir gqlorm && cd gqlorm
  • go mod init gqlorm
  • graphql-orm init

then it panic:

Initializing project in . ...
Generating contents from [model.graphql] ...
Appending content from model file model.graphql
Running gqlgen generator in gen ...
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x18 pc=0x8961bc]

goroutine 1 [running]:
github.com/99designs/gqlgen/codegen/config.(*TypeReference).IsPtr(...)
        ~/go/pkg/mod/github.com/99designs/[email protected]/codegen/config/binder.go:207
github.com/99designs/gqlgen/codegen.(*builder).buildField(0xc0006bbb20, 0xc000532280, 0xc000313260, 0x0, 0xef46e0, 0xc00090d900)
        ~/go/pkg/mod/github.com/99designs/[email protected]/codegen/field.go:70 +0x35c
github.com/99designs/gqlgen/codegen.(*builder).buildObject(0xc0006bbb20, 0xc00031a600, 0x0, 0x0, 0x1)
        ~/go/pkg/mod/github.com/99designs/[email protected]/codegen/object.go:73 +0x4a4
github.com/99designs/gqlgen/codegen.BuildData(0xc0002aa000, 0xafc640, 0xef3658, 0x0)
        ~/go/pkg/mod/github.com/99designs/[email protected]/codegen/data.go:68 +0x478
github.com/99designs/gqlgen/api.Generate(0xc0002aa000, 0x0, 0x0, 0x0, 0x0, 0x20)
        ~/go/pkg/mod/github.com/99designs/[email protected]/api/generate.go:72 +0x361
github.com/99designs/gqlgen/cmd.glob..func1(0xc000282240, 0xc000292200, 0x0)
        ~/go/pkg/mod/github.com/99designs/[email protected]/cmd/gen.go:38 +0x93
github.com/urfave/cli/v2.(*App).RunContext(0xc000290000, 0xb07d20, 0xc000024100, 0xc0000201e0, 0x1, 0x1, 0x0, 0x0)
        ~/go/pkg/mod/github.com/urfave/cli/[email protected]/app.go:311 +0x70b
github.com/urfave/cli/v2.(*App).Run(...)
        ~/go/pkg/mod/github.com/urfave/cli/[email protected]/app.go:211
github.com/99designs/gqlgen/cmd.Execute()
        ~/go/pkg/mod/github.com/99designs/[email protected]/cmd/root.go:41 +0x1f1
main.main()
        ~/go/pkg/mod/github.com/99designs/[email protected]/main.go:8 +0x20
exit status 2
exit status 1

generate model / error

Hi,

I tried to generate a graphql model for prestashop but it triggers the following error

➜  prestashop-graphql-orm git:(main) ✗ make generate
GO111MODULE=on go run github.com/novacloudcz/graphql-orm
Generating contents from [model.graphql] ...
Appending content from model file model.graphql
Running gqlgen generator in gen ...
schemaconfig: schema.graphql:16: expected at least one definition, found }
exit status 3
exit status 1
exit status 1
make: *** [generate] Error 1

can you help me to sort it out ?

Thanks for any insights or inputs on that.

Ps. here is my model:

schema {
  query: RootQueryType
  mutation: RootMutationType
}

scalar Upload

type Cart {
  products: [CartProduct]
  total: String
}

input CartOption {
  id: String
  value: String
}

type CartProductOption {
    name: String
    value: String
    type: String
}

type CartProduct {
  key: String
  product: Product
  option: [CartProductOption]
  quantity: Int
  total: String
}

type Category {
  id: ID
  image: String
  imageLazy: String
  name: String
  description: String
  parent_id: String
  url(url: String): String
  categories(limit: Int = 3): [Category]
  keyword: String
  meta: Meta
}

type categoryBlog {
  id: ID
  image: String
  imageLazy: String
  name: String
  description: String
  parent_id: String
  url(url: String): String
  keyword: String
  categories(limit: Int = 3): [categoryBlog]
  meta: Meta
}

type categoryBlogResult {
  content: [categoryBlog]
  first: Boolean
  last: Boolean
  number: Int
  numberOfElements: Int
  size: Int
  totalPages: Int
  totalElements: Int
}

type CategoryResult {
  content: [Category]
  first: Boolean
  last: Boolean
  number: Int
  numberOfElements: Int
  size: Int
  totalPages: Int
  totalElements: Int
}

type Currency {
  title: String @deprecated(reason: "Changed to name!")
  name: String
  code: String
  symbol_left: String
  symbol_right: String
  active: Boolean
}

type Customer {
  id: String
  firstName: String
  lastName: String
  email: String
}

input CustomerInput {
  firstName: String
  lastName: String
  email: String
  password: String
}

type Language {
  name: String
  code: String
  image: String
  active: Boolean
}

type LoggedResult {
  status: Boolean
  customer: Customer
}

type LogoutResult {
  status: Boolean
}

type OptionValue {
  id: String
  name: String
}

type Page {
  id: ID
  title: String @deprecated(reason: "Changed to name!")
  name: String
  description: String
  keyword: String
  meta: Meta
  sort_order: Int
}

type PageResult {
  content: [Page]
  first: Boolean
  last: Boolean
  number: Int
  numberOfElements: Int
  size: Int
  totalPages: Int
  totalElements: Int
}

type postReviewResult {
  content: [postReview]
  totalElements: Int
}

type Post {
  id: ID
  title: String @deprecated(reason: "Changed to name!")
  name: String
  shortDescription: String
  description: String
  image: String
  imageLazy: String
  keyword: String
  rating: Float
  reviews: postReviewResult
  categories: [categoryBlog]
  datePublished: String
  next: Post
  prev: Post
  meta: Meta
}

type PostResult {
  content: [Post]
  first: Boolean
  last: Boolean
  number: Int
  numberOfElements: Int
  size: Int
  totalPages: Int
  totalElements: Int
}

type postReview {
  author: String
  author_email: String
  content: String
  created_at: String
  rating: Float
}

type Country {
    id: ID
    name: String
}
type Zone {
    id: ID
    name: String
    countryId: String
}

type Product {
  products(limit: Int = 3): [Product]
  id: ID
  image: String
  imageLazy: String
  imageBig: String
  name: String
  shortDescription: String
  description: String
  model: String
  price: String
  special: String
  tax: String
  minimum: Int
  stock: Boolean
  rating: Float
  attributes: [productAttribute]
  reviews: [ProductReview]
  options: [ProductOption]
  images(limit: Int = 3): [productImage]
  keyword: String
  meta: Meta
}

type productAttribute {
  name: String
  options: [String]
}

type productImage {
  image: String
  imageLazy: String
  imageBig: String
}

type ProductOption {
  id: String
  name: String
  type: String
  values: [OptionValue]
}

type ProductResult {
  content: [Product]
  first: Boolean
  last: Boolean
  number: Int
  numberOfElements: Int
  size: Int
  totalPages: Int
  totalElements: Int
}
type CountriesResult {
  content: [Country]
  first: Boolean
  last: Boolean
  number: Int
  numberOfElements: Int
  size: Int
  totalPages: Int
  totalElements: Int
}
type ZonesResult {
  content: [Zone]
  first: Boolean
  last: Boolean
  number: Int
  numberOfElements: Int
  size: Int
  totalPages: Int
  totalElements: Int
}

type ProductReview {
  author: String
  author_email: String
  content: String
  created_at: String
  rating: Float
}

type ContactResult {
    status: Boolean
}

type Location {
    image: String
    imageLazy: String
    address: String
    geocode: String
    telephone: String
    fax: String
    open: String
    comment: String
}

type Contact {
    locations: [Location]
    store: String
    address: String
    email: String
    geocode: String
    telephone: String
    fax: String
    open: String
    comment: String
}

type AccountAddress {
  id: String
  firstName: String
  lastName: String
  company: String
  address1: String
  address2: String
  zoneId: String
  zone: Zone
  countryId: String
  country: Country
  city: String
  zipcode: String
}

input AccountAddressInput {
  firstName: String
  lastName: String
  company: String
  address1: String
  address2: String
  city: String
  countryId: String
  zoneId: String
  zipcode: String
}

type FileResult {
  code: String
}

type CheckoutLinkResult {
  link: String
}

type Meta {
    title: String
    description: String
    keyword: String
}

type HomeResult {
    meta: Meta
}

type LoginResult {
  token: String
  customer: Customer
}

type FieldValue {
    text: String
    value: String
}

type AddressField {
  type: String
  name: String
  label: String
  required: Boolean
  values: [FieldValue]
}

type ShippingMethod {
  id: String
  codename: String
  name: String
}

type PaymentMethod {
  id: String
  codename: String
  name: String
}

input InputField {
  name: String
  value: String
}

type CreateOrderResult {
  success: String
}

type UpdateOrderResult {
  paymentMethods: [PaymentMethod]
  shippingMethods: [ShippingMethod]
  totals: [Total]
}

type ConfirmOrderResult {
  order: Order
  url: String
}

type Order {
  id: String
}

type PaymentAddressResult {
  fields: [AddressField]
  agree: String
}

type Total {
  title: String
  text: String
}

type RootMutationType {
  uploadFile(file: Upload): FileResult
  accountLogin(email: String, password: String): LoginResult
  accountLogout: LogoutResult
  accountRegister(customer: CustomerInput): Customer
  accountEdit(customer: CustomerInput): Customer
  accountEditPassword(password: String): Customer
  accountAddAddress(address: AccountAddressInput): AccountAddress
  accountEditAddress(id: String, address: AccountAddressInput): AccountAddress
  accountRemoveAddress(id: String, page: Int = 1, size: Int = 10): [AccountAddress]
  addBlogPostReview(id: String, rating: Float, author: String, content: String): Post
  addToCart(id: String, quantity: Int = 1, options: [CartOption] = []): Cart
  updateCart(key: String, quantity: Int = 1): Cart
  removeCart(key: String): Cart
  addToCompare(id: Int): [Product]
  removeCompare(id: String): [Product]
  editCurrency(code: String): [Currency]
  editLanguage(code: String): [Language]
  addReview(id: String, rating: Float, author: String, content: String): Product
  addToWishlist(id: Int): [Product]
  removeWishlist(id: String): [Product]
  contactSend(name: String, email: String, message: String): ContactResult
  createOrder: CreateOrderResult
  updateOrder(paymentAddress: [InputField], shippingAddress: [InputField], paymentMethod: String, shippingMethod: String): UpdateOrderResult
  confirmOrder: ConfirmOrderResult

}

type RootQueryType {
  shippingMethods: [ShippingMethod]
  paymentMethods: [PaymentMethod]
  paymentAddress: PaymentAddressResult
  shippingAddress: [AddressField]
  totals: [Total]
  home: HomeResult
  zone(id: Int): Zone
  zonesList(page: Int = 1, size: Int = 10, search: String, country_id: String, sort: String = "name", order: String = "ASC"): ZonesResult
  country(id: Int): Country
  countriesList(page: Int = 1, size: Int = 10, search: String, sort: String = "name", order: String = "ASC"): CountriesResult
  categoryBlog(id: String): categoryBlog
  categoriesBlogList(page: Int = 1, size: Int = 10, filter: String, parent: Int = -1, sort: String = "sort_order", order: String = "ASC"): categoryBlogResult
  post(id: String): Post
  postsList(page: Int = 1, size: Int = 10, filter: String, search: String, category_id: String = "", sort: String = "sort_order", order: String = "ASC"): PostResult
  cart: Cart
  category(id: String): Category
  categoriesList(page: Int = 1, size: Int = 10, filter: String, parent: Int = -1, sort: String = "sort_order", order: String = "ASC"): CategoryResult
  compare: [Product]
  currency: [Currency]
  language: [Language]
  page(id: String): Page
  pagesList(page: Int = 1, size: Int = 10, search: String = "", sort: String = "sort_order", order: String = "ASC"): PageResult
  productsList(page: Int = 1, size: Int = 15, filter: String = "", special: Boolean = false, search: String = "", ids: [Int] = [], category_id: String = "", sort: String = "sort_order", order: String = "ASC"): ProductResult
  product(id: String): Product
  wishlist: [Product]
  contact: Contact
  accountCheckLogged: LoggedResult
  accountAddressList: [AccountAddress]
  accountAddress(id: String): AccountAddress
  checkoutLink: CheckoutLinkResult
}


Forwarding directives to input types

Currently it's possible to specify custom directives for fields. They are propagated to the final schema, but only for type fields. We need a way how to specify custom directives that need to be used for input fields (eg. for validation purposes).

Example:

// model.graphql
type User {
  email: String! @validation(email: true)
  age: Int @validation(min: 0) 
}

// gen/schema.graphql
input UserCreateInput {
  id: ID
  email: String! @validation(email: true)
  age: Int @validation(min: 0) 
}

input UserUpdateInput {
  email: String @validation(email: true)
  age: Int @validation(min: 0) 
}

The question is how to choose which directives propagate to type fields and which to create/update input fields (I'm not sure if it's ok to propagate them all).

github.com/99designs/gqlgen The latest version (v0.11.1) reports an error

Update github.com/99designs/gqlgen to the latest version (v0.11.1) and run make generate to report an error.
Take a look and updated the github.com/vektah/gqlparser package to github.com/vektah/gqlparser/v2

Following is github.com/99designs/gqlgen v0.9.1 run
image

Following is github.com/99designs/gqlgen v0.11.1 run
image

master latest code generation error

Generating contents from model.graphql ...
Running gqlgen generator in gen ...
schemaconfig: schema.graphql:16: expected at least one definition, found }
exit status 3
exit status 1
exit status 1

image

image

image

assignment mismatch: 2 variables but client.Send returns 3 values

After running below command
go run github.com/novacloudcz/graphql-orm init
I am getting this error message
# github.com/novacloudcz/graphql-orm/events ../../../github.com/novacloudcz/graphql-orm/events/controller.go:52:13: assignment mismatch: 2 variables but client.Send returns 3 values

Using go version : go1.13.4 linux/amd64

Congratulations!

Hi @jakubknejzlik,

I have nothing interesting to write because I discovered your project a little while ago.

It dazzled me!

CONGRATULATIONS! REALLY!

It is one of the most beautiful Go projects I discovered in recent months.

Please continue! Do not stop!

And thank you for what you teach the world.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.