Skip to content
This repository has been archived by the owner on Nov 15, 2022. It is now read-only.

GraphQL #270

Open
wants to merge 74 commits into
base: master
Choose a base branch
from
Open

GraphQL #270

wants to merge 74 commits into from

Conversation

lucassabreu
Copy link
Member

@lucassabreu lucassabreu commented Aug 3, 2018

connected to #297

Essa é uma implementação dos handlers que existem usando a lib github.com/graphql-go/graphql, não foram implementados os endpoints de contato/e-mail e afins por enquanto, para tentar evitar demorar mais com o PR que o humanamente aceitável.

Se puderem dar uma olhada (talvez testar o uso) eu agradeceria.


O GraphiQL foi alterado para suportar o envio do token de autorização:

image


Full Schema:

# source: http://localhost:8000/graphql
# timestamp: Fri Aug 03 2018 13:57:35 GMT-0300 (Horário Padrão de Brasília)

schema {
  query: RootQuery
  mutation: RootMutation
}

type Address {
  city: String
  complement: String
  neighbordhood: String
  number: String
  state: String
  street: String
  zipcode: String
}

input AddressInput {
  """When set to true, will make the address without a complement"""
  withoutComplement: Boolean = false
  street: String
  number: String
  complement: String
  neighbordhood: String
  city: String
  state: String
  zipcode: String
}

type Category {
  id: Int!
  name: String!
  needsCount: Int!
  slug: String!
}

"""
The `Date` scalar type represents a Date with the format "yyyy-mm-dd". The Date is serialized as an string
"""
scalar Date

"""
The `DateTime` scalar represents a Date time string supported by the RFC 3339.
"""
scalar DateTime

type LoginResult {
  organization: Organization
  token: String!
}

type Need {
  category: Category
  createdAt: DateTime!
  description: String
  dueDate: Date
  id: Int!
  images: [NeedImage!]
  organization: Organization
  reachedQuantity: Int
  requiredQuantity: Int
  status: NeedStatus
  title: String!
  unit: String
  updatedAt: DateTime
}

input NeedCreateInput {
  unit: String!
  dueDate: Date
  categoryId: Int!
  title: String!
  description: String
  requiredQuantity: Int = 0
  reachedQuantity: Int = 0
}

type NeedCreatePayload {
  need: Need
}

type NeedImage {
  id: Int!
  name: String!
  url: String!
}

input NeedImageCreateInput {
  needId: Int!
  file: Upload!
}

type NeedImageCreatePayload {
  needImage: NeedImage
}

input NeedImageDeleteInput {
  needId: Int!
  needImageId: Int!
}

type NeedImageDeletePayload {
  need: Need
}

input NeedPatchInput {
  title: String
  description: String
  requiredQuantity: Int
  unit: String
  categoryId: Int
  status: NeedStatus

  """When set to true, will make the need without a description"""
  withoutDescription: Boolean = false

  """When set to true, will make the need without date limit"""
  withoutDueDate: Boolean = false
  reachedQuantity: Int
  dueDate: Date
}

"""Status of a Need"""
enum NeedStatus {
  """A inactive Need"""
  INACTIVE

  """A active Need"""
  ACTIVE
}

input NeedUpdateInput {
  patch: NeedPatchInput!
  id: Int!
}

type NeedUpdatePayload {
  need: Need
}

type Organization {
  about: String!
  address: Address!
  email: String!
  id: Int!
  images: [OrganizationImage]
  logo: String
  name: String!
  needs(input: SearchOrganizationNeedsInput): PaginatedNeedsPayload
  phone: String!
  slug: String!
  video: String!
  website: String
}

type OrganizationImage {
  id: Int!
  name: String!
  url: String!
}

input OrganizationImageCreateInput {
  file: Upload!
}

type OrganizationImageCreatePayload {
  organizationImage: OrganizationImage
}

input OrganizationImageDeleteInput {
  organizationImageId: Int!
}

type OrganizationImageDeletePayload {
  organization: Organization
}

input OrganizationUpdateInput {
  phone: String
  about: String
  video: String
  email: String
  address: AddressInput
  name: String
}

type OrganizationUpdatePayload {
  organization: Organization
}

type PageInfo {
  currentPage: Int!
  totalPages: Int!
  totalResults: Int!
}

type PaginatedNeedsPayload {
  pageInfo: PageInfo
  results: [Need!]
}

type ResetPasswordPayload {
  organization: Organization
}

type RootMutation {
  """
  Authenticate the user and returns a token and organization if succeded
  """
  login(email: String!, password: String!): LoginResult

  """Mutations that need authentication"""
  viewer: ViewerMutations
}

type RootQuery {
  """Return all Categories"""
  allCategories: [Category]

  """Retrieves a Category by its ID"""
  category(id: Int!): Category

  """Retrieves a Need by its Id"""
  need(id: Int!): Need

  """Retrieves a Organization by its Id"""
  organization(id: Int!): Organization

  """Search active needs on the database"""
  search(input: SearchNeedsInput): PaginatedNeedsPayload

  """Authorized Organization"""
  viewer: Organization
}

input SearchNeedsInput {
  page: Int = 1
  text: String
  categories: [Int!]
  organizationId: Int
  status: NeedStatus
  orderBy: SearchOrderBy
  order: SearchOrder
}

"""Order will be accending or descending"""
enum SearchOrder {
  ASC
  DESC
}

"""Which kind of ordering will be used"""
enum SearchOrderBy {
  """Order by Need's ID"""
  ID

  """Order by Last Need's Update date"""
  UPDATED_AT

  """Order by Need's Creation date"""
  CREATED_AT
}

input SearchOrganizationNeedsInput {
  categories: [Int!]
  orderBy: SearchOrderBy
  status: NeedStatus
  order: SearchOrder
  page: Int = 1
  text: String
}

input UpdatePasswordInput {
  currentPassword: String!
  newPassword: String!
}

type UpdatePasswordPayload {
  organization: Organization
}

"""
The `Upload` scalar represents a uploaded file using "multipart/form-data" as
described in the spec:
(https://github.com/jaydenseric/graphql-multipart-request-spec/tree/v2.0.0)
"""
scalar Upload

type ViewerMutations {
  """Creates a need for the token Organization"""
  needCreate(input: NeedCreateInput): NeedCreatePayload

  """Creates a image for the need"""
  needImageCreate(input: NeedImageCreateInput): NeedImageCreatePayload

  """Deletes a image from the need"""
  needImageDelete(input: NeedImageDeleteInput): NeedImageDeletePayload

  """Updates a need with the patch"""
  needUpdate(input: NeedUpdateInput): NeedUpdatePayload

  """Creates a image for the current organization"""
  organizationImageCreate(input: OrganizationImageCreateInput): OrganizationImageCreatePayload

  """Deletes a image from the current organization"""
  organizationImageDelete(input: OrganizationImageDeleteInput): OrganizationImageDeletePayload

  """Updates Organization Profile"""
  organizationUpdate(input: OrganizationUpdateInput): OrganizationUpdatePayload

  """Reset the Organizations password to a new password"""
  resetPassword(newPassword: String!): ResetPasswordPayload

  """Updates the current user password"""
  updatePassword(input: UpdatePasswordInput): UpdatePasswordPayload
}

@lucassabreu lucassabreu mentioned this pull request Aug 3, 2018
98 tasks

-- +migrate Up
UPDATE needs SET updated_at = created_at WHERE updated_at IS NULL;
ALTER TABLE needs ALTER COLUMN updated_at SET NOT NULL;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Com essa ideia não teria que setar o default da coluna updated_at como now?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

na hora de criar, sim, olhando agora acho que tem algum problema ou as linhas

err = r.db.QueryRow(
`INSERT INTO needs (category_id, organization_id, title, description, required_qtd, reached_qtd, due_date, status, unit, updated_at)
VALUES($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)
RETURNING id
`,
n.CategoryID,
n.OrganizationID,
n.Title,
n.Description,
n.RequiredQuantity,
n.ReachedQuantity,
n.DueDate,
n.Status,
n.Unit,
n.UpdatedAt,
).Scan(&n.ID)
não precisavam de alteração ou o created_at esta errado, vou dar uma olhada


v1.HandleFunc("/auth/login", AuthHandler.Login)

v1.Path("/auth/update-password").Handler(authMiddleware.With(
v1.Path("/auth/update-password").Handler(privateMiddleware.With(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Precisam existir esses endpoint agora que tudo vai ser graphql?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

para o frontend não precisar migrar de uma vez sim, depois que eles migrarem podemos tirar eles

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ahhh boaa 👍

if c, ok := categoryCache.Load(id); ok {
return c.(model.Category), nil
c := c.(*model.Category)
return c, nil
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why? não entendi porque a mudança

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

não tinha um endpoint para procurar a categoria antes, isso fazia com que fosse meio impossível de não achar uma quando vc procurasse, jah que ela estaria vinculada a uma need, ou vindo pelo GetAll... como agora pode usar o query category(id) para buscar a categoria, achei melhor deixar ela semelhante ao resto

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Beleza 👍

@Coderockr Coderockr deleted a comment Aug 7, 2018
@Coderockr Coderockr deleted a comment Aug 7, 2018
@Coderockr Coderockr deleted a comment Aug 7, 2018
@Coderockr Coderockr deleted a comment Aug 7, 2018
@Coderockr Coderockr deleted a comment Jan 15, 2019
@Coderockr Coderockr deleted a comment Jun 13, 2019
@Coderockr Coderockr deleted a comment Jun 13, 2019
@Coderockr Coderockr deleted a comment Jun 13, 2019
@Coderockr Coderockr deleted a comment Jun 13, 2019
@Coderockr Coderockr deleted a comment Oct 7, 2019
@Coderockr Coderockr deleted a comment Oct 7, 2019
@Coderockr Coderockr deleted a comment Oct 7, 2019
@Coderockr Coderockr deleted a comment Oct 7, 2019
@coderockrdev
Copy link
Collaborator

Codacy Here is an overview of what got changed by this pull request:

Issues
======
- Added 4
           

Complexity increasing per file
==============================
- server/db/repo/organization.go  8
- server/graphql/organizationUpdateMutation.go  19
- server/graphql/viewerQuery.go  2
- server/graphql/needImageDeleteMutation.go  2
- server/graphql/needCreateMutation.go  4
- server/graphql/categoryQuery.go  4
- server/graphql/graphql_test.go  7
- server/graphql/loginMutation.go  4
- server/graphql/resetPasswordMutation.go  4
- server/graphql/organizationQuery.go  2
- server/graphql/allCategoriesQuery.go  2
- server/graphql/scalar.go  6
- server/graphql/needImageCreateMutation.go  3
- server/graphql/viewerMutation.go  1
- server/graphql/organizationImageDeleteMutation.go  2
- server/graphql/searchQuery.go  6
- server/graphql/graphiql-middleware.go  4
- server/graphql/graphql.go  3
- server/graphql/needQuery.go  10
- server/graphql/updatePasswordMutation.go  4
- server/graphql/needUpdateMutation.go  20
- server/graphql/organizationImageCreateMutation.go  3
         

See the complete overview on Codacy

@Coderockr Coderockr deleted a comment Nov 26, 2019
@@ -139,7 +128,18 @@ type SearchNeed struct {
CategorySlug string `db:"category_slug"`
}

func (s *needStatus) Scan(src interface{}) error {
type NeedStatus string
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -163,6 +163,6 @@ func (s *needStatus) Scan(src interface{}) error {
return nil
}

func (s needStatus) Value() (driver.Value, error) {
func (s NeedStatus) Value() (driver.Value, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NeedStatusEmpty = NeedStatus("")
)

func (s *NeedStatus) Scan(src interface{}) error {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ALTER TABLE needs ALTER COLUMN updated_at SET NOT NULL;

-- +migrate Down
ALTER TABLE needs ALTER COLUMN updated_at SET NULL;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants