Skip to content
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

Integration with strawberry (graphql queries) and pydastic (elastic search). #516

Open
8 tasks done
khairm opened this issue Dec 16, 2022 · 1 comment
Open
8 tasks done
Labels
feature New feature or request

Comments

@khairm
Copy link

khairm commented Dec 16, 2022

First Check

  • I added a very descriptive title to this issue.
  • I used the GitHub search to find a similar issue and didn't find it.
  • I searched the SQLModel documentation, with the integrated search.
  • I already searched in Google "How to X in SQLModel" and didn't find any information.
  • I already read and followed all the tutorial in the docs and didn't find an answer.
  • I already checked if it is not related to SQLModel but to Pydantic.
  • I already checked if it is not related to SQLModel but to SQLAlchemy.

Commit to Help

  • I commit to help with one of those options 👆

Example Code

-

Description

As per title. Would be great if we had one model that could work with pydastic and strawberry queries. Maybe I'm naïve....

Wanted Solution

I would want execute strawberry and pydastic queries/insertions on a SQLModel.

Wanted Code

-

Alternatives

Asking the same in the the strawberry and pydastic repos.
Creating a new project to incorporate all 3....

Operating System

Windows

Operating System Details

Windows 11 home

SQLModel Version

0.0.8

Python Version

3.10

Additional Context

strawberry-graphql/strawberry#1183

Might be some code/additional context here.

@khairm khairm added the feature New feature or request label Dec 16, 2022
@ljluestc
Copy link

ljluestc commented Sep 3, 2023

from sqlmodel import SQLModel, Field
from strawberry import schema, ID

Define your SQLModel

class Item(SQLModel, table=True):
id: int = Field(default=None, primary_key=True)
name: str

Define Pydantic model for validation

class ItemPydantic(BaseModel):
name: str

Define Strawberry GraphQL schema

@Schema
class ItemSchema:
id: ID
name: str

Define Strawberry GraphQL query

@strawberry.type
class Query:
@strawberry.field
def get_item(self, id: int) -> ItemSchema:
item = get_item_by_id(id) # Implement this function
return ItemSchema(id=item.id, name=item.name)

Define Strawberry GraphQL mutation

@strawberry.type
class Mutation:
@strawberry.mutation
def create_item(self, name: str) -> ItemSchema:
item = create_item(name) # Implement this function
return ItemSchema(id=item.id, name=item.name)

Create Strawberry GraphQL⬤

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants